diff --git a/lib/aspects/token.js b/lib/aspects/token.js index a9167d292..44d2bdf77 100644 --- a/lib/aspects/token.js +++ b/lib/aspects/token.js @@ -1125,9 +1125,9 @@ function syncUserInfoWechatMp(_a, context) { var _b, _c, _d; var nickname = _a.nickname, avatarUrl = _a.avatarUrl, encryptedData = _a.encryptedData, iv = _a.iv, signature = _a.signature; return tslib_1.__awaiter(this, void 0, void 0, function () { - var userId, application, config, _e, _f, sessionKey, user; - return tslib_1.__generator(this, function (_g) { - switch (_g.label) { + var userId, application, config, _e, _f, sessionKey, user, _g, type, config2, _h, appId, appSecret, wechatInstance, result; + return tslib_1.__generator(this, function (_j) { + switch (_j.label) { case 0: userId = context.getToken().userId; application = context.getApplication(); @@ -1169,28 +1169,17 @@ function syncUserInfoWechatMp(_a, context) { dontCollect: true, })]; case 1: - _e = tslib_1.__read.apply(void 0, [_g.sent(), 1]), _f = _e[0], sessionKey = _f.sessionKey, user = _f.user; - // console.log(avatarUrl); - // const { type, config } = application; - // assert(type === 'wechatMp' || config.type === 'wechatMp'); - // const config2 = config as WechatMpConfig; - // const { appId, appSecret } = config2; - // const wechatInstance = WechatSDK.getInstance(appId, 'wechatMp', appSecret); - // const result = wechatInstance.decryptData(sessionKey as string, encryptedData, iv, signature); + _e = tslib_1.__read.apply(void 0, [_j.sent(), 1]), _f = _e[0], sessionKey = _f.sessionKey, user = _f.user; + _g = application, type = _g.type, config2 = _g.config; + (0, assert_1.assert)(type === 'wechatMp' || config2.type === 'wechatMp'); + _h = config2, appId = _h.appId, appSecret = _h.appSecret; + wechatInstance = oak_external_sdk_1.WechatSDK.getInstance(appId, 'wechatMp', appSecret); + result = wechatInstance.decryptData(sessionKey, encryptedData, iv, signature); // 实测发现解密出来的和userInfo完全一致…… - // console.log(result); + console.log(result); return [4 /*yield*/, setUserInfoFromWechat(user, { nickname: nickname, avatar: avatarUrl }, context)]; case 2: - // console.log(avatarUrl); - // const { type, config } = application; - // assert(type === 'wechatMp' || config.type === 'wechatMp'); - // const config2 = config as WechatMpConfig; - // const { appId, appSecret } = config2; - // const wechatInstance = WechatSDK.getInstance(appId, 'wechatMp', appSecret); - // const result = wechatInstance.decryptData(sessionKey as string, encryptedData, iv, signature); - // 实测发现解密出来的和userInfo完全一致…… - // console.log(result); - _g.sent(); + _j.sent(); return [2 /*return*/]; } }); diff --git a/lib/endpoints/wechat.js b/lib/endpoints/wechat.js index 06b32733c..26da9ea71 100644 --- a/lib/endpoints/wechat.js +++ b/lib/endpoints/wechat.js @@ -293,12 +293,21 @@ function setUserSubscribed(openId, eventKey, context) { time: "".concat(Date.now()), }); content = "".concat(name_1, "\u4E3A\u60A8\u521B\u5EFA\u4E86\u4E00\u4E2A\u6388\u6743\uFF0C\u8BF7\u70B9\u51FB\u9886\u53D6"); - (0, assert_1.default)(!expired_1); // 如果生成的wechatQrCode没过期,userEntityGrant就不可能过期。 - wechatInstance.sendServeMessage({ - openId: openId, - type: 'text', - content: content, - }); + // assert(!expired); // 如果生成的wechatQrCode没过期,userEntityGrant就不可能过期。 + if (!expired_1) { + wechatInstance.sendServeMessage({ + openId: openId, + type: 'text', + content: content, + }); + } + else { + wechatInstance.sendServeMessage({ + openId: openId, + type: 'text', + content: '您好,您扫描的二维码已经过期,请联系管理员重新获取', + }); + } return [3 /*break*/, 9]; case 7: return [4 /*yield*/, context.select('domain', { data: { @@ -329,15 +338,24 @@ function setUserSubscribed(openId, eventKey, context) { scene: sceneStr, time: "".concat(Date.now()), }); - (0, assert_1.default)(!expired_1); // 如果生成的wechatQrCode没过期,userEntityGrant就不可能过期。 - wechatInstance.sendServeMessage({ - openId: openId, - type: 'news', - url: url, - title: "".concat(name_1, "\u4E3A\u60A8\u521B\u5EFA\u4E86\u4E00\u4E2A\u6388\u6743"), - description: '请接受', - picurl: 'http://img95.699pic.com/element/40018/2473.png_860.png', - }); + // assert(!expired); // 如果生成的wechatQrCode没过期,userEntityGrant就不可能过期。 + if (!expired_1) { + wechatInstance.sendServeMessage({ + openId: openId, + type: 'news', + url: url, + title: "".concat(name_1, "\u4E3A\u60A8\u521B\u5EFA\u4E86\u4E00\u4E2A\u6388\u6743"), + description: '请接受', + picurl: 'http://img95.699pic.com/element/40018/2473.png_860.png', + }); + } + else { + wechatInstance.sendServeMessage({ + openId: openId, + type: 'text', + content: '您好,您扫描的二维码已经过期,请联系管理员重新获取', + }); + } _k.label = 9; case 9: return [3 /*break*/, 11]; case 10: diff --git a/lib/locales/Common/locales/zh_CN.json b/lib/locales/Common/locales/zh_CN.json index 1472d4f33..fc2a74a6e 100644 --- a/lib/locales/Common/locales/zh_CN.json +++ b/lib/locales/Common/locales/zh_CN.json @@ -14,7 +14,8 @@ "cancel": "取消", "grant": "授权", "revoke": "回收", - "tip": "提示" + "tip": "提示", + "detail": "详情" }, "reset": "重置", "select": "查询", diff --git a/src/aspects/token.ts b/src/aspects/token.ts index 425d842ae..833508f5e 100644 --- a/src/aspects/token.ts +++ b/src/aspects/token.ts @@ -950,15 +950,15 @@ export async function syncUserInfoWechatMp; - // assert(type === 'wechatMp' || config.type === 'wechatMp'); + assert(type === 'wechatMp' || config2!.type === 'wechatMp'); // const config2 = config as WechatMpConfig; - // const { appId, appSecret } = config2; - // const wechatInstance = WechatSDK.getInstance(appId, 'wechatMp', appSecret); - // const result = wechatInstance.decryptData(sessionKey as string, encryptedData, iv, signature); + const { appId, appSecret } = config2 as WechatMpConfig; + const wechatInstance = WechatSDK.getInstance(appId, 'wechatMp', appSecret); + const result = wechatInstance.decryptData(sessionKey as string, encryptedData, iv, signature); // 实测发现解密出来的和userInfo完全一致…… - // console.log(result); + console.log(result); await setUserInfoFromWechat(user!, { nickname, avatar: avatarUrl }, context); } diff --git a/src/endpoints/wechat.ts b/src/endpoints/wechat.ts index 58ee2c518..34b0b0109 100644 --- a/src/endpoints/wechat.ts +++ b/src/endpoints/wechat.ts @@ -303,12 +303,21 @@ async function setUserSubscribed(openId: string, eventKey: string, context: BRC) // 先试着发文字链接 const content = `${name}为您创建了一个授权,请点击领取`; - assert(!expired); // 如果生成的wechatQrCode没过期,userEntityGrant就不可能过期。 - wechatInstance.sendServeMessage({ - openId, - type: 'text', - content, - }); + // assert(!expired); // 如果生成的wechatQrCode没过期,userEntityGrant就不可能过期。 + if (!expired) { + wechatInstance.sendServeMessage({ + openId, + type: 'text', + content, + }); + } else { + wechatInstance.sendServeMessage({ + openId, + type: 'text', + content: '您好,您扫描的二维码已经过期,请联系管理员重新获取', + }); + } + } else { // 推domain上的scan/code链接 @@ -341,15 +350,23 @@ async function setUserSubscribed(openId: string, eventKey: string, context: BRC) time: `${Date.now()}`, }); - assert(!expired); // 如果生成的wechatQrCode没过期,userEntityGrant就不可能过期。 - wechatInstance.sendServeMessage({ - openId, - type: 'news', - url, - title: `${name}为您创建了一个授权`, - description: '请接受', - picurl: 'http://img95.699pic.com/element/40018/2473.png_860.png', - }); + // assert(!expired); // 如果生成的wechatQrCode没过期,userEntityGrant就不可能过期。 + if (!expired) { + wechatInstance.sendServeMessage({ + openId, + type: 'news', + url, + title: `${name}为您创建了一个授权`, + description: '请接受', + picurl: 'http://img95.699pic.com/element/40018/2473.png_860.png', + }); + } else { + wechatInstance.sendServeMessage({ + openId, + type: 'text', + content: '您好,您扫描的二维码已经过期,请联系管理员重新获取', + }); + } } } } diff --git a/src/locales/Common/locales/zh_CN.json b/src/locales/Common/locales/zh_CN.json index ec85e33dd..1798b73da 100644 --- a/src/locales/Common/locales/zh_CN.json +++ b/src/locales/Common/locales/zh_CN.json @@ -14,7 +14,8 @@ "cancel": "取消", "grant": "授权", "revoke": "回收", - "tip": "提示" + "tip": "提示", + "detail": "详情" }, "reset": "重置", "select": "查询",