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

add wechat check

parent aec897e6
Pipeline #15259 passed with stage
in 37 seconds
...@@ -10,9 +10,35 @@ class WechatController extends Controller { ...@@ -10,9 +10,35 @@ class WechatController extends Controller {
} }
async callbackAction() { async callbackAction() {
const {ctx, service} = this; const { ctx, service } = this;
await service.course.wechat.callbackAction(); await service.course.wechat.callbackAction();
ctx.success(); ctx.success('success');
}
async check() {
const { ctx } = this;
const params = ctx.request.query;
const {
signature,
timestamp,
nonce,
echostr,
} = params;
const array = [ '51gjj', timestamp, nonce ];
array.sort();
// 3.将三个参数字符串拼接成一个字符串进行sha1加密
const tempStr = array.join('');
const hashCode = crypto.createHash('sha1'); // 创建加密类型
const resultCode = hashCode.update(tempStr, 'utf8').digest('hex');
// 4.开发者获得加密后的字符串可与signature对比,标识该请求来源于微信
if (resultCode === signature) {
ctx.success(echostr);
} else {
ctx.failed();
}
} }
} }
......
...@@ -28,6 +28,6 @@ module.exports = app => { ...@@ -28,6 +28,6 @@ module.exports = app => {
router.post('third', '/user/collection/institution', miniAuth, 'course.user.collectInstitution');// 收藏机构 router.post('third', '/user/collection/institution', miniAuth, 'course.user.collectInstitution');// 收藏机构
router.delete('third', '/user/collection/institution', miniAuth, 'course.user.delCollectInstitution');// 取消收藏机构 router.delete('third', '/user/collection/institution', miniAuth, 'course.user.delCollectInstitution');// 取消收藏机构
router.get('third', '/wechat/callbackAction', 'course.wechat.callbackAction'); router.get('third', '/wechat/callbackAction', 'course.wechat.check');
router.post('third', '/wechat/callbackAction', miniAuth, 'course.wechat.callbackAction');
}; };
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