liuyu пре 4 година
родитељ
комит
8e62012dc7
2 измењених фајлова са 21 додато и 10 уклоњено
  1. 11 10
      app/service/weixin.js
  2. 10 0
      config/config.default.js

+ 11 - 10
app/service/weixin.js

@@ -17,20 +17,21 @@ class WeixinAuthService extends AxiosService {
     // TODO:参数检查和默认参数处理
     assert(code);
     const { wxapi } = this.app.config;
-    let res = await this.httpGet('/api/fetch', { code });
+
+    const reqUrl = 'https://api.weixin.qq.com/sns/oauth2/access_token';
+    const params = {
+      appid: wxapi.appid,
+      secret: wxapi.appSecret,
+      code,
+      grant_type: 'authorization_code',
+    };
+    const res = await this.httpGet(reqUrl, params);
+
     if (res.errcode && res.errcode !== 0) {
       this.ctx.logger.error(`[WeixinAuthService] fetch open by code fail, errcode: ${res.errcode}, errmsg: ${res.errmsg}`);
       throw new BusinessError(ErrorCode.SERVICE_FAULT, '获得微信认证信息失败');
     }
-    const { openid } = res;
-
-    // TODO: 获得用户信息
-    res = await this.httpGet('/api.weixin.qq.com/cgi-bin/user/info?lang=zh_CN', { appid: wxapi.appid, openid });
-    // console.debug('res: ', res);
-    if (res.errcode && res.errcode !== 0) {
-      this.ctx.logger.error(`[WeixinAuthService] fetch userinfo by openid fail, errcode: ${res.errcode}, errmsg: ${res.errmsg}`);
-      throw new BusinessError(ErrorCode.SERVICE_FAULT, '获得微信用户信息失败');
-    }
+    // const { openid } = res;
     return res;
   }
 

+ 10 - 0
config/config.default.js

@@ -39,6 +39,16 @@ module.exports = appInfo => {
     },
   };
 
+  config.wxapi = {
+    appid: 'wxdf3ed83c095be97a', // 微信公众号APPID
+    appSecret: '6f949b09f27d62103ef1db1ec8d3ea1c',
+    baseUrl: 'http://wx.cc-lotus.info', // 微信网关地址
+    mchid: '1505364491', // 商户ID
+    mchkey: '1qaz2wsx3edc4rfv5tgb6yhn7ujm8ik9', // 商户key
+    wxurl: 'http://free.liaoningdoupo.com/api/wxpayback',
+    payurl: 'https://api.mch.weixin.qq.com/pay/unifiedorder',
+  };
+
   config.proxy = true;
   config.hostHeaders = 'x-forwarded-host';
   // 服务器发布路径