|
@@ -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;
|
|
|
}
|
|
|
|