Commit c3c93d4e authored by 任国军's avatar 任国军

add wechat check

parent b453edda
Pipeline #15264 passed with stage
in 36 seconds
......@@ -34,6 +34,7 @@ class WechatController extends Controller {
const hashCode = crypto.createHash('sha1'); // 创建加密类型
const resultCode = hashCode.update(tempStr, 'utf8').digest('hex');
console.log(resultCode);
// 4.开发者获得加密后的字符串可与signature对比,标识该请求来源于微信
if (resultCode === signature) {
ctx.success(echostr);
......
......@@ -29,5 +29,5 @@ module.exports = app => {
router.delete('third', '/user/collection/institution', miniAuth, 'course.user.delCollectInstitution');// 取消收藏机构
router.get('third', '/wechat/callbackAction', 'course.wechat.check');
router.post('third', '/wechat/callbackAction', miniAuth, 'course.wechat.callbackAction');
router.post('third', '/wechat/callbackAction', 'course.wechat.callbackAction');
};
......@@ -24,16 +24,16 @@ class WechatService extends Service {
async callbackAction() {
const { ctx } = this;
ctx.logger.info('course_wechat_receive: ' + JSON.stringify(ctx));
await this.sendMsg();
await this.sendMsg(ctx.request.body);
}
async sendMsg() {
async sendMsg(data) {
const { ctx } = this;
const token = await this.getAccessToken();
const url = 'https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=' + token;
const params = {
access_token: token,
touser: ctx.openId,
touser: data.FromUserName,
msgtype: 'text',
text: { content: 'hello world' },
};
......
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