|
|
@@ -1596,6 +1596,71 @@ class ApiController {
|
|
|
msg: "success",
|
|
|
};
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ //小程序SDK接入
|
|
|
+ //游光文档:http://platform-doc.ttwmz.com/docs/channel/channel/awy/xyx-fear-end.html#%E9%89%B4%E6%9D%83
|
|
|
+ miniAppDomain = "wefunol.com ";
|
|
|
+ //登录鉴权
|
|
|
+ async wxLogin(ctx) {
|
|
|
+ try {
|
|
|
+ let data = ctx.request.body;
|
|
|
+ let token = data.token;
|
|
|
+ let loginUrl = `https://wxlogin.${this.miniAppDomain}.com/wxlogin?cmd=checkUserToken&token=${token}`
|
|
|
+ let wxLogin = await axios.get(loginUrl);
|
|
|
+
|
|
|
+ ctx.body = {
|
|
|
+ code: 0,
|
|
|
+ msg: "success",
|
|
|
+ data: wxLogin.data,
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ console.error('wxLogin error:', error);
|
|
|
+ ctx.body = {
|
|
|
+ code: -1,
|
|
|
+ msg: error.message || "登录验证失败",
|
|
|
+ data: null,
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 小程序签名函数
|
|
|
+ generateSignature(parameters, privateKey) {
|
|
|
+ // 1. 过滤掉空值和sign参数
|
|
|
+ const filteredParams = parameters.filter(param => {
|
|
|
+ const [key, value] = param.split('=');
|
|
|
+ return key !== 'sign' && value && value.trim() !== '';
|
|
|
+ });
|
|
|
+
|
|
|
+ // 2. 对参数进行URL编码
|
|
|
+ const encodedParams = filteredParams.map(param => {
|
|
|
+ const [key, value] = param.split('=');
|
|
|
+ const encodedValue = encodeURIComponent(value);
|
|
|
+ return `${key}=${encodedValue}`;
|
|
|
+ });
|
|
|
+
|
|
|
+ // 3. 按字母顺序排序
|
|
|
+ encodedParams.sort((a, b) => {
|
|
|
+ return a.localeCompare(b);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 4. 用&连接所有参数
|
|
|
+ const queryString = encodedParams.join('&');
|
|
|
+
|
|
|
+ // 5. 拼接私钥
|
|
|
+ const stringToSign = `${queryString}&key=${privateKey}`;
|
|
|
+
|
|
|
+ // 6. 计算MD5并转大写
|
|
|
+ const signature = CryptoJS.MD5(stringToSign).toString().toUpperCase();
|
|
|
+
|
|
|
+ return signature;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
}
|
|
|
|
|
|
module.exports = new ApiController();
|