|
@@ -53,19 +53,11 @@ class WeixinAuthService extends AxiosService {
|
|
|
async authBack(query) {
|
|
|
const { code, state } = query;
|
|
|
if (!code) throw new BusinessError(ErrorCode.SERVICE_FAULT, '授权未成功');
|
|
|
- const { appid, appSecret } = this.wxInfo;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- console.log(code);
|
|
|
+ const { appid } = this.wxInfo;
|
|
|
const req = await this.httpGet('/api/fetch', { code });
|
|
|
if (req.errcode && req.errcode !== 0) throw new BusinessError(ErrorCode.SERVICE_FAULT, 'openid获取失败');
|
|
|
const openid = _.get(req, 'openid');
|
|
|
+ console.log(req);
|
|
|
const access_token = await this.app.redis.get(this.access_tokenKey);
|
|
|
if (!access_token) await this.app.redis.set(this.access_tokenKey, _.get(req, 'access_token'), 'EX', 6000);
|
|
|
if (!openid) {
|
|
@@ -73,10 +65,9 @@ class WeixinAuthService extends AxiosService {
|
|
|
throw new BusinessError(ErrorCode.SERVICE_FAULT, '未获取到openid');
|
|
|
}
|
|
|
|
|
|
- console.log({ access_token, appid, openid });
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ const res = await this.httpGet('/api.weixin.qq.com/cgi-bin/user/info?lang=zh_CN', { appid, openid });
|
|
|
+ const object = _.pick(res, [ 'nickname', 'headimgurl', 'openid' ]);
|
|
|
+ console.log(object);
|
|
|
|
|
|
const key = `${this.prefix}${state}`;
|
|
|
let fqueries = await this.app.redis.get(key);
|
|
@@ -87,12 +78,12 @@ class WeixinAuthService extends AxiosService {
|
|
|
if (groupid) {
|
|
|
if (type === 'group') {
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ const udata = { name: object.nickname, icon: object.headimgurl, openid: object.openid, groupid };
|
|
|
+ try {
|
|
|
+ await this.ctx.service.patient.create(udata);
|
|
|
+ } catch (error) {
|
|
|
+ this.logger.error(error);
|
|
|
+ }
|
|
|
redirect_uri = `${this.ctx.app.config.baseUrl}/mobile`;
|
|
|
} else {
|
|
|
|