Commit 6e1cfb4c by 宋毅

tj

parent ac313f1d
......@@ -14,5 +14,13 @@ class ChannelAccessAuthAPI extends APIBase {
var opResult = await this.utilsuserSve.getH5AliDingUserByCode(pobj);
return opResult;
}
/**
* 获取钉钉鉴权信息
* actionBody code授权码
*/
async getDingJsApiAuthInfo(pobj, qobj, req) {
var opResult = await this.utilsuserSve.getDingJsApiAuthentication(pobj);
return opResult;
}
}
module.exports = ChannelAccessAuthAPI;
\ No newline at end of file
......@@ -55,7 +55,6 @@ class utilsTlBankSve extends AppServiceBase {
return signature;
}
//-------------------------------------------钉钉h5支付-----------------结束
}
......
var system = require("../../../system");
var settings = require("../../../../config/settings");
const AppServiceBase = require("../../app.base");
const cryptoJS = require("crypto-js");
//商标查询操作
class UtilsUserSve extends AppServiceBase {
constructor() {
super();
this.redisClient = system.getObject("util.redisClient");
this.apppaliparamDao = system.getObject("db.dbapp.apppaliparamDao");
this.logCtl = system.getObject("service.common.oplogSve");
}
......@@ -13,25 +15,11 @@ class UtilsUserSve extends AppServiceBase {
if (!item) {
return system.getResult(null, "应用对应的配置数据为空!");
}
var param = {
appkey: item.appkey,
appsecret: item.appsecret
};
var accessTokenResult = await this.execGetUrl(param, "https://oapi.dingtalk.com/gettoken");
this.logCtl.info({
appid: pobj.appInfo ? pobj.appInfo.uapp_id : "",
appkey: pobj.appInfo ? pobj.appInfo.uapp_key : "",
op: "https://oapi.dingtalk.com/gettoken",
content: "参数:" + JSON.stringify(param) + "返回结果:" + JSON.stringify(accessTokenResult),
optitle: "获取钉钉access_token信息返回",
});
var accessTokenResult = await this.getDingAccessToken(pobj, item);
if (accessTokenResult.status != 0) {
return accessTokenResult;
}
if (accessTokenResult.data.errcode != 0) {
return system.getResult(null, accessTokenResult.data.errmsg);
}
param = {
var param = {
access_token: accessTokenResult.data.access_token,
code: pobj.actionBody.code
};
......@@ -56,5 +44,100 @@ class UtilsUserSve extends AppServiceBase {
});
}
/**
* 获取钉钉jsapi鉴权的参数
* @param {*} pobj
* @param {*} actionBody
*/
async getDingJsApiAuthentication(pobj) {
var item = await this.apppaliparamDao.getItemByUAppId(pobj.appInfo.uapp_id);
if (!item) {
return { status: -310, msg: "应用没有对应的支付凭证" }
}
var accessTokenResult = await this.getDingAccessToken(pobj, item);
if (accessTokenResult.status != 0) {
return accessTokenResult;
}
var ticketResult = await this.getDingTicket(pobj, item, accessTokenResult.data.access_token);
if (ticketResult.status != 0) {
return ticketResult;
}
var timeStamp = Date.now();
var nonceStr = await this.getBusUid("sy");
var nowPageUrl = pobj.actionBody && pobj.actionBody.nowPageUrl ? pobj.actionBody.nowPageUrl : "http://alitm.qifu.gongsibao.com";
var parameters = {
agentId: item.agent_id,
corpId: item.corp_id,
timeStamp: timeStamp.toString(),
nonceStr: nonceStr
};
var signature = await this.getJsApiSingnature(ticketResult.data.ticket, parameters.nonceStr, parameters.timeStamp, nowPageUrl);
parameters.signature = signature;
return system.getResultSuccess(parameters);
}
async getDingAccessToken(pobj, item) {//获取钉钉access_token----本类中调用
var param = {
appkey: item.appkey,
appsecret: item.appsecret
};
var accessTokenResult = await this.execGetUrl(param, "https://oapi.dingtalk.com/gettoken");
this.logCtl.info({
appid: pobj.appInfo ? pobj.appInfo.uapp_id : "",
appkey: pobj.appInfo ? pobj.appInfo.uapp_key : "",
op: "https://oapi.dingtalk.com/gettoken",
content: "参数:" + JSON.stringify(param) + "返回结果:" + JSON.stringify(accessTokenResult),
optitle: "获取钉钉access_token信息返回",
});
if (accessTokenResult.status != 0) {
return accessTokenResult;
}
if (accessTokenResult.data.errcode != 0) {
return system.getResult(null, accessTokenResult.data.errmsg);
}
return accessTokenResult;
}
async getDingTicket(pobj, item, access_token) {//获取钉钉jsapi_ticket----本类中调用
var ticketCachekey = settings.cacheprefix + "_ali-ticket:" + item.appkey;
var cacheValue = await this.redisClient.get(ticketCachekey);
if (cacheValue && cacheValue != "undefined" && cacheValue != "null") {
return JSON.parse(cacheValue)
}
var param = {
access_token: access_token
};
var ticketResult = await this.execGetUrl(param, "https://oapi.dingtalk.com/get_jsapi_ticket");
this.logCtl.info({
appid: pobj.appInfo ? pobj.appInfo.uapp_id : "",
appkey: pobj.appInfo ? pobj.appInfo.uapp_key : "",
op: "https://oapi.dingtalk.com/get_jsapi_ticket",
content: "参数:" + JSON.stringify(param) + "返回结果:" + JSON.stringify(ticketResult),
optitle: "获取钉钉jsapi_ticket信息返回",
});
if (ticketResult.status != 0) {
return ticketResult;
}
if (ticketResult.data.errcode != 0) {
return system.getResult(null, ticketResult.data.errmsg);
}
var expireTime = ticketResult.data.expires_in || 20;
this.redisClient.setWithEx(ticketCachekey, JSON.stringify(ticketResult), expireTime);
return ticketResult;
}
/**
* 获取JsApi鉴权签名信息----本类中调用
* @param {*} ticket
* @param {*} nonce
* @param {*} timeStamp
* @param {*} url
*/
async getJsApiSingnature(ticket, nonce, timeStamp, url) {//获取JsApi鉴权签名信息----本类中调用
let plainTex = "jsapi_ticket=" + ticket + "&noncestr=" + nonce + "&timestamp=" + timeStamp + "&url=" + url;
let signature = cryptoJS.SHA1(plainTex).toString();
return signature;
}
}
module.exports = UtilsUserSve;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment