Commit c56073b3 by 庄冰

wxtoken

parent c7d131de
......@@ -40,6 +40,9 @@ class PolicyAPI extends APIBase {
case "submitPolicyNeedNotes"://申请信息备注提交
opResult = this.policySve.submitPolicyNeedNotes(pobj);
break;
case "getWxToken"://申请信息备注提交
opResult = this.policySve.getWxToken();
break;
default:
opResult = system.getResult(null, "action_type参数错误");
break;
......
const CacheBase=require("../cache.base");
const system=require("../../system");
// const OpenplatformWxop = require("../../wxop/impl/openplatformWxop");
/**
* 微信开放平台 公众号或小程序的接口调用凭据(授权方令牌)缓存(2小时后失效)
*/
class WxTokenCache extends CacheBase{
constructor(){
super();
this.prefix="wx_policy_token_wx8aa8a8d4ff3da8bd";
this.restClient = system.getObject("util.restClient");
this.wxTokenSve = system.getObject("service.common.wxTokenSve");
}
desc() {
return "应用UI配置缓存";
}
prefix() {
return "wx_policy_token_wx8aa8a8d4ff3da8bd";
}
async get(){//公众号appid
var key = this.prefix;
var result = await this.redisClient.get(key);
var obj = null;
if(result){
obj=JSON.parse(result);
}
if(!obj){//无缓存
var newobj = await this.wxTokenSve.getToken();
if(newobj && newobj.access_token){
var newobjstring=JSON.stringify(newobj);
await this.redisClient.rpushWithEx(key,newobjstring,30);
return newobj;
}else{
return null;
}
}
return obj;
}
}
module.exports=WxTokenCache;
\ No newline at end of file
const system = require("../../../system");
var settings = require("../../../../config/settings");
/**
* 微信token
* zhuangbing
* 2020.02.17
*/
class WxTokenService{
constructor(){
this.rc=system.getObject("util.execClient");
}
/**
* 获取微信access_token
* 返回结果:
* component_access_token 第三方平台access_token
* expires_in 有效期
*/
async getToken(){
try{
var url="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx8aa8a8d4ff3da8bd&secret=5b64d43832cfd08327e9369aa455f799";
var rtn=await this.rc.execGet({},url);
console.log(rtn);
var result=JSON.parse(rtn.stdout);
return result;
}catch(e){
return null;
}
}
}
module.exports=WxTokenService;
\ No newline at end of file
......@@ -4,7 +4,15 @@ class PolicyService{
constructor() {
this.centerOrderUrl = settings.centerOrderUrl();
this.execClient = system.getObject("util.execClient");
this.cacheManager = system.getObject("db.common.cacheManager");
};
async getWxToken(){
var data = await this.cacheManager["WxTokenCache"].get();
if(data){
return system.getResultSuccess(data);
}
return system.getResult();
}
async policyQuery(pobj) {
var url = this.centerOrderUrl + "action/policy/springBoard";
var rtn = await this.execClient.execPost(pobj, url);
......
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