You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.9 KiB
71 lines
1.9 KiB
import Malls from "./js/Malls";
|
|
import Coupons from "./js/Coupons";
|
|
import CryptoJS from "./crypto-js";
|
|
|
|
App({
|
|
async onLaunch() {
|
|
this.malls = new Malls();
|
|
this.coupons = new Coupons();
|
|
this.globalData = {};
|
|
},
|
|
async getOpenid() {
|
|
if (this.openid) return this.openid;
|
|
const apiKey = "29EXdde5aOT7kFE4KLMtGYvIjgT";
|
|
const apiSecret = "bf3fd4a5d79744e8ad87ca6b8c665277";
|
|
const date = new Date();
|
|
let sign = function (timestamp, params) {
|
|
console.log("请求参数");
|
|
console.log(params);
|
|
// 排序参数
|
|
const sortParamsEncode = Object.keys(params)
|
|
.sort()
|
|
.map((key) => `${key}=${params[key]}`)
|
|
.join("&");
|
|
console.log("排序参数");
|
|
console.log(sortParamsEncode);
|
|
// 加密字符串
|
|
const encryptStr = sortParamsEncode + "|" + timestamp + "|" + apiKey;
|
|
console.log("加密字符串");
|
|
console.log(encryptStr);
|
|
// 加密
|
|
const digest = CryptoJS.enc.Base64.stringify(
|
|
CryptoJS.HmacSHA256(encryptStr, apiSecret)
|
|
);
|
|
console.log("加密值");
|
|
console.log(digest);
|
|
return digest;
|
|
};
|
|
const { code } = await new Promise((resolve, reject) => {
|
|
wx.login({
|
|
success: resolve,
|
|
fail: reject,
|
|
});
|
|
});
|
|
let timestamp = date.toISOString();
|
|
const body = {
|
|
mallCode: "wx1949744ebf85151fwx1949744ebf85151f",
|
|
code,
|
|
};
|
|
|
|
const signature = sign(timestamp, body);
|
|
|
|
const { data } = await new Promise((resolve) =>
|
|
wx.request({
|
|
url: `https://api.1000my.com/wxmp/session`,
|
|
method: "POST",
|
|
data: body,
|
|
header: {
|
|
"x-qm-apikey": apiKey,
|
|
"x-qm-datetime": timestamp,
|
|
"x-qm-signature": signature,
|
|
"Content-Type": "application/json",
|
|
},
|
|
success: resolve,
|
|
})
|
|
);
|
|
console.log(data);
|
|
|
|
this.openid = data.openid;
|
|
return this.openid;
|
|
},
|
|
});
|
|
|