Browse Source

feat: 添加微信公众号登录和支付功能

新增微信公众号登录授权流程,包括获取签名和用户信息
实现微信公众号支付功能,支持H5环境和小程序环境
添加微信分享功能,支持朋友圈、好友和微博分享
更新.gitignore文件,排除node_modules和package-lock.json
优化支付逻辑,统一处理小程序和H5环境的支付接口
hfll
前端-胡立永 3 weeks ago
parent
commit
05c840afc1
12 changed files with 2012 additions and 60 deletions
  1. +3
    -1
      .gitignore
  2. +5
    -0
      App.vue
  3. +12
    -0
      api/modules/login.js
  4. +3
    -2
      manifest.json
  5. +8
    -8
      pages.json
  6. +149
    -35
      subPages/login/login.vue
  7. +3
    -0
      subPages/member/recharge.vue
  8. +86
    -14
      utils/common.js
  9. +733
    -0
      utils/lib/jweixin-module.js
  10. +876
    -0
      utils/lib/md5.js
  11. +47
    -0
      utils/pay.js
  12. +87
    -0
      utils/share.js

+ 3
- 1
.gitignore View File

@ -1 +1,3 @@
unpackage/
unpackage/
node_modules/
package-lock.json

+ 5
- 0
App.vue View File

@ -1,4 +1,5 @@
<script>
import share from '@/utils/share.js'
export default {
methods: {
//
@ -18,6 +19,10 @@
onLaunch() {
//
this.getQrcode()
// #ifdef H5
share()
// #endif
},
async onShow() {
// if(!uni.getStorageSync('token')){


+ 12
- 0
api/modules/login.js View File

@ -24,6 +24,18 @@ export default {
})
},
// 获取公众号签名
async getSignPackage(data) {
return http({
url: '/login/getSignPackage',
method: 'POST',
data,
// header: {
// 'Content-Type': 'application/x-www-form-urlencoded'
// },
})
},
// 获取用户信息
async getUserInfo() {
return http({


+ 3
- 2
manifest.json View File

@ -1,6 +1,6 @@
{
"name" : "四零语境",
"appid" : "__UNI__B264FE1",
"appid" : "__UNI__197A38F",
"description" : "四零语境",
"versionName" : "1.0.0",
"versionCode" : "100",
@ -51,7 +51,8 @@
/* H5 */
"h5" : {
"devServer" : {
"port" : 8002
"port" : 8002,
"disableHostCheck": true
}
},
/* */


+ 8
- 8
pages.json View File

@ -162,26 +162,26 @@
{
"pagePath": "pages/index/home",
"text": "主页",
"iconPath": "static/主页图标.png",
"selectedIconPath": "static/主页图标-点击.png"
"iconPath": "/static/主页图标.png",
"selectedIconPath": "/static/主页图标-点击.png"
},
{
"pagePath": "pages/index/desk",
"text": "书桌",
"iconPath": "static/书桌图标.png",
"selectedIconPath": "static/书桌图标-点击.png"
"iconPath": "/static/书桌图标.png",
"selectedIconPath": "/static/书桌图标-点击.png"
},
{
"pagePath": "pages/index/member",
"text": "会员",
"iconPath": "static/会员图标.png",
"selectedIconPath": "static/会员图标-点击.png"
"iconPath": "/static/会员图标.png",
"selectedIconPath": "/static/会员图标-点击.png"
},
{
"pagePath": "pages/index/user",
"text": "我的",
"iconPath": "static/我的图标.png",
"selectedIconPath": "static/我的图标-点击.png"
"iconPath": "/static/我的图标.png",
"selectedIconPath": "/static/我的图标-点击.png"
}
]
}


+ 149
- 35
subPages/login/login.vue View File

@ -65,57 +65,171 @@ export default {
isAgreed: false
}
},
mounted() {
// #ifdef H5
// H5URL
this.checkWechatAuthCallback();
// #endif
},
methods: {
//
//
handleLogin() {
if (!this.isAgreed) {
this.$refs.serviceModal.open();
this.$refs.guideModal.open();
return
}
// #ifdef MP-WEIXIN
//
this.miniProgramLogin();
// #endif
// #ifdef H5
// H5 -
this.wechatOfficialLogin();
// #endif
},
//
miniProgramLogin() {
uni.login({
provider: 'weixin',
success: async (res) => {
console.log('登录成功', res);
const obj = { }
if (uni.getStorageSync('inviter')){
obj.inviter = uni.getStorageSync('inviter')
}
const { result: loginRes } = await this.$api.login.login({
code: res.code,
...obj
})
uni.setStorageSync('token', loginRes.token)
const userInfo = loginRes.userInfo
// store
this.$store.dispatch('updateUserInfo', userInfo)
if ( !userInfo.avatar || !userInfo.name || !userInfo.phone ){
uni.navigateTo({
url: '/subPages/login/userInfo'
})
return
}else {
uni.showToast({
title: '登录成功',
icon: 'success'
})
uni.switchTab({
url: '/pages/index/home'
});
}
//
console.log('小程序登录成功', res);
await this.processLogin(res.code);
},
fail: (err) => {
console.log('登录失败', err);
console.log('小程序登录失败', err);
uni.showToast({
title: '登录失败',
icon: 'none'
});
}
})
},
//
wechatOfficialLogin() {
console.log('开始微信公众号授权登录');
// URL
const appId = this.configParamContent('official_appid') || 'your_wechat_appid'; // AppID
const redirectUri = encodeURIComponent(window.location.origin + window.location.pathname + '#/subPages/login/login');
console.log('redirectUri:', window.location.origin + window.location.pathname + '#/subPages/login/login');
const state = Date.now().toString();
//
if (uni.getStorageSync('inviter')) {
sessionStorage.setItem('temp_inviter', uni.getStorageSync('inviter'));
}
const authUrl = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${redirectUri}&response_type=code&scope=snsapi_userinfo&state=${state}#wechat_redirect`;
console.log('跳转到微信授权页面:', authUrl);
window.location.href = authUrl;
},
//
checkWechatAuthCallback() {
const code = this.getUrlParameter('code');
const state = this.getUrlParameter('state');
if (code && state) {
console.log('检测到微信授权回调, code:', code, 'state:', state);
//
const tempInviter = sessionStorage.getItem('temp_inviter');
if (tempInviter) {
uni.setStorageSync('inviter', tempInviter);
sessionStorage.removeItem('temp_inviter');
}
//
this.processLogin(code, 'official');
}
},
//
async processLogin(code, type = 'miniprogram') {
try {
const loginParams = {
code: code
};
//
if (uni.getStorageSync('inviter')) {
loginParams.inviter = uni.getStorageSync('inviter');
}
//
if (type === 'official') {
loginParams.type = 'official';
}
console.log('登录参数:', loginParams);
const { result: loginRes } = await this.$api.login.login(loginParams);
uni.setStorageSync('token', loginRes.token);
const userInfo = loginRes.userInfo;
// store
this.$store.dispatch('updateUserInfo', userInfo);
if (!userInfo.avatar || !userInfo.name || !userInfo.phone) {
uni.navigateTo({
url: '/subPages/login/userInfo'
});
return;
} else {
uni.showToast({
title: '登录成功',
icon: 'success'
});
uni.switchTab({
url: '/pages/index/home'
});
}
} catch (error) {
console.error('登录失败:', error);
uni.showToast({
title: '登录失败,请重试',
icon: 'none'
});
// #ifdef H5
// H5URL
if (this.getUrlParameter('code')) {
const cleanUrl = window.location.origin + window.location.pathname + window.location.hash.split('?')[0];
window.history.replaceState({}, document.title, cleanUrl);
}
// #endif
}
},
// URL
getUrlParameter(name) {
// #ifdef H5
const url = window.location.href;
try {
const urlParams = new URLSearchParams(window.location.search);
return urlParams.get(name) || '';
} catch (e) {
//
const regex = new RegExp('[?&]' + name + '(=([^&#]*)|&|#|$)');
const results = regex.exec(url);
if (!results) return '';
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, ' '));
}
// #endif
// #ifndef H5
return '';
// #endif
},
//


+ 3
- 0
subPages/member/recharge.vue View File

@ -190,6 +190,9 @@
// console.log('id:', this.packageList[this.selectedPackage]);
const object = {
// #ifdef H5
type : 'official',
// #endif
memberId: this.list[this.selectedMember].id,
setmealId: this.packageList[this.selectedPackage].id
}


+ 86
- 14
utils/common.js View File

@ -47,12 +47,20 @@ const calculateDateDifference = (dateString) => {
return dayDifference
}
// 微信支付方法
// 传参1: 支付数据
// 传参2: 成功回调
// 传参3: 失败回调
// 传三个参数 支付数据 成功回调 失败回调
const wxPay = (paymentData, successCallback, failCallback) => {
// #ifdef H5
import jWeixin from './lib/jweixin-module.js'
// #endif
/**
* 微信支付方法 - 支持小程序和公众号多环境
* @param {Object} paymentData - 支付数据对象
* @param {Function} successCallback - 成功回调函数
* @param {Function} failCallback - 失败回调函数
* @returns {Promise} - H5环境返回Promise小程序环境直接执行回调
*/
const wxPay = (paymentData, successCallback, failCallback) => {
// #ifdef MP-WEIXIN
// 小程序环境使用uni.requestPayment
uni.requestPayment({
provider: 'wxpay',
timeStamp: paymentData.timeStamp,
@ -61,10 +69,7 @@ const wxPay = (paymentData, successCallback, failCallback) => {
signType: paymentData.signType,
paySign: paymentData.paySign,
success: (res) => {
if (successCallback) {
successCallback(res)
}
console.log('支付成功:', res)
console.log('小程序支付成功:', res)
uni.showToast({
title: '支付成功',
icon: 'success'
@ -74,10 +79,7 @@ const wxPay = (paymentData, successCallback, failCallback) => {
}
},
fail: (err) => {
console.log('支付失败:', err)
if (failCallback) {
failCallback(err)
}
console.log('小程序支付失败:', err)
if (err.errMsg === 'requestPayment:fail cancel') {
uni.showToast({
title: '支付已取消',
@ -89,8 +91,78 @@ const wxPay = (paymentData, successCallback, failCallback) => {
icon: 'none'
})
}
if (failCallback) {
failCallback(err)
}
}
})
// #endif
// #ifdef H5
// H5环境使用微信JSSDK
return new Promise((resolve, reject) => {
// JSSDK配置成功后的回调
jWeixin.ready(function() {
// 调用微信支付接口
jWeixin.chooseWXPay({
appId: paymentData.appId,
timestamp: paymentData.timeStamp, // 支付签名时间戳
nonceStr: paymentData.nonceStr, // 支付签名随机串
package: paymentData.packageValue, // 统一支付接口返回的prepay_id参数值
signType: paymentData.signType, // 签名类型,默认为MD5
paySign: paymentData.paySign, // 支付签名
success: function(result) {
console.log('H5支付成功:', result)
uni.showToast({
title: '支付成功',
icon: 'success'
})
if (successCallback) {
successCallback(result)
}
resolve(result)
},
fail: function(error) {
console.log('H5支付失败:', error)
uni.showToast({
title: '支付失败',
icon: 'none'
})
if (failCallback) {
failCallback(error)
}
reject(error)
},
cancel: function(error) {
console.log('H5支付取消:', error)
uni.showToast({
title: '支付已取消',
icon: 'none'
})
const cancelError = { type: 'cancel', ...error }
if (failCallback) {
failCallback(cancelError)
}
reject(cancelError)
}
})
})
// JSSDK配置失败处理
jWeixin.error(function(error) {
console.log('JSSDK配置失败:', error)
uni.showToast({
title: 'JSSDK配置失败',
icon: 'none'
})
const configError = { type: 'config_error', ...error }
if (failCallback) {
failCallback(configError)
}
reject(configError)
})
})
// #endif
}
export {


+ 733
- 0
utils/lib/jweixin-module.js View File

@ -0,0 +1,733 @@
! function(e, n) {
"function" == typeof define && (define.amd || define.cmd) ? define(function() {
return n(e)
}) : n(e, !0)
}(window, function(o, e) {
if (!o.jWeixin) {
var n, c = {
config: "preVerifyJSAPI",
onMenuShareTimeline: "menu:share:timeline",
onMenuShareAppMessage: "menu:share:appmessage",
onMenuShareQQ: "menu:share:qq",
onMenuShareWeibo: "menu:share:weiboApp",
onMenuShareQZone: "menu:share:QZone",
previewImage: "imagePreview",
getLocation: "geoLocation",
openProductSpecificView: "openProductViewWithPid",
addCard: "batchAddCard",
openCard: "batchViewCard",
chooseWXPay: "getBrandWCPayRequest",
openEnterpriseRedPacket: "getRecevieBizHongBaoRequest",
startSearchBeacons: "startMonitoringBeacons",
stopSearchBeacons: "stopMonitoringBeacons",
onSearchBeacons: "onBeaconsInRange",
consumeAndShareCard: "consumedShareCard",
openAddress: "editAddress"
},
a = function() {
var e = {};
for (var n in c) e[c[n]] = n;
return e
}(),
i = o.document,
t = i.title,
r = navigator.userAgent.toLowerCase(),
s = navigator.platform.toLowerCase(),
d = !(!s.match("mac") && !s.match("win")),
u = -1 != r.indexOf("wxdebugger"),
l = -1 != r.indexOf("micromessenger"),
p = -1 != r.indexOf("android"),
f = -1 != r.indexOf("iphone") || -1 != r.indexOf("ipad"),
m = (n = r.match(/micromessenger\/(\d+\.\d+\.\d+)/) || r.match(/micromessenger\/(\d+\.\d+)/)) ? n[1] :
"",
g = {
initStartTime: L(),
initEndTime: 0,
preVerifyStartTime: 0,
preVerifyEndTime: 0
},
h = {
version: 1,
appId: "",
initTime: 0,
preVerifyTime: 0,
networkType: "",
isPreVerifyOk: 1,
systemType: f ? 1 : p ? 2 : -1,
clientVersion: m,
url: encodeURIComponent(location.href)
},
v = {},
S = {
_completes: []
},
y = {
state: 0,
data: {}
};
O(function() {
g.initEndTime = L()
});
var I = !1,
_ = [],
w = {
config: function(e) {
B("config", v = e);
var t = !1 !== v.check;
O(function() {
if (t) M(c.config, {
verifyJsApiList: C(v.jsApiList),
verifyOpenTagList: C(v.openTagList)
}, function() {
S._complete = function(e) {
g.preVerifyEndTime = L(), y.state = 1, y.data = e
}, S.success = function(e) {
h.isPreVerifyOk = 0
}, S.fail = function(e) {
S._fail ? S._fail(e) : y.state = -1
};
var t = S._completes;
return t.push(function() {
! function() {
if (!(d || u || v.debug || m < "6.0.2" || h
.systemType < 0)) {
var i = new Image;
h.appId = v.appId, h.initTime = g.initEndTime -
g.initStartTime, h.preVerifyTime = g
.preVerifyEndTime - g.preVerifyStartTime, w
.getNetworkType({
isInnerInvoke: !0,
success: function(e) {
h.networkType = e
.networkType;
var n =
"https://open.weixin.qq.com/sdk/report?v=" +
h.version + "&o=" + h
.isPreVerifyOk + "&s=" +
h.systemType + "&c=" + h
.clientVersion + "&a=" +
h.appId + "&n=" + h
.networkType + "&i=" + h
.initTime + "&p=" + h
.preVerifyTime + "&u=" +
h.url;
i.src = n
}
})
}
}()
}), S.complete = function(e) {
for (var n = 0, i = t.length; n < i; ++n) t[n]();
S._completes = []
}, S
}()), g.preVerifyStartTime = L();
else {
y.state = 1;
for (var e = S._completes, n = 0, i = e.length; n < i; ++n) e[n]();
S._completes = []
}
}), w.invoke || (w.invoke = function(e, n, i) {
o.WeixinJSBridge && WeixinJSBridge.invoke(e, x(n), i)
}, w.on = function(e, n) {
o.WeixinJSBridge && WeixinJSBridge.on(e, n)
})
},
ready: function(e) {
0 != y.state ? e() : (S._completes.push(e), !l && v.debug && e())
},
error: function(e) {
m < "6.0.2" || (-1 == y.state ? e(y.data) : S._fail = e)
},
checkJsApi: function(e) {
M("checkJsApi", {
jsApiList: C(e.jsApiList)
}, (e._complete = function(e) {
if (p) {
var n = e.checkResult;
n && (e.checkResult = JSON.parse(n))
}
e = function(e) {
var n = e.checkResult;
for (var i in n) {
var t = a[i];
t && (n[t] = n[i], delete n[i])
}
return e
}(e)
}, e))
},
onMenuShareTimeline: function(e) {
P(c.onMenuShareTimeline, {
complete: function() {
M("shareTimeline", {
title: e.title || t,
desc: e.title || t,
img_url: e.imgUrl || "",
link: e.link || location.href,
type: e.type || "link",
data_url: e.dataUrl || ""
}, e)
}
}, e)
},
onMenuShareAppMessage: function(n) {
P(c.onMenuShareAppMessage, {
complete: function(e) {
"favorite" === e.scene ? M("sendAppMessage", {
title: n.title || t,
desc: n.desc || "",
link: n.link || location.href,
img_url: n.imgUrl || "",
type: n.type || "link",
data_url: n.dataUrl || ""
}) : M("sendAppMessage", {
title: n.title || t,
desc: n.desc || "",
link: n.link || location.href,
img_url: n.imgUrl || "",
type: n.type || "link",
data_url: n.dataUrl || ""
}, n)
}
}, n)
},
onMenuShareQQ: function(e) {
P(c.onMenuShareQQ, {
complete: function() {
M("shareQQ", {
title: e.title || t,
desc: e.desc || "",
img_url: e.imgUrl || "",
link: e.link || location.href
}, e)
}
}, e)
},
onMenuShareWeibo: function(e) {
P(c.onMenuShareWeibo, {
complete: function() {
M("shareWeiboApp", {
title: e.title || t,
desc: e.desc || "",
img_url: e.imgUrl || "",
link: e.link || location.href
}, e)
}
}, e)
},
onMenuShareQZone: function(e) {
P(c.onMenuShareQZone, {
complete: function() {
M("shareQZone", {
title: e.title || t,
desc: e.desc || "",
img_url: e.imgUrl || "",
link: e.link || location.href
}, e)
}
}, e)
},
updateTimelineShareData: function(e) {
M("updateTimelineShareData", {
title: e.title,
link: e.link,
imgUrl: e.imgUrl
}, e)
},
updateAppMessageShareData: function(e) {
M("updateAppMessageShareData", {
title: e.title,
desc: e.desc,
link: e.link,
imgUrl: e.imgUrl
}, e)
},
startRecord: function(e) {
M("startRecord", {}, e)
},
stopRecord: function(e) {
M("stopRecord", {}, e)
},
onVoiceRecordEnd: function(e) {
P("onVoiceRecordEnd", e)
},
playVoice: function(e) {
M("playVoice", {
localId: e.localId
}, e)
},
pauseVoice: function(e) {
M("pauseVoice", {
localId: e.localId
}, e)
},
stopVoice: function(e) {
M("stopVoice", {
localId: e.localId
}, e)
},
onVoicePlayEnd: function(e) {
P("onVoicePlayEnd", e)
},
uploadVoice: function(e) {
M("uploadVoice", {
localId: e.localId,
isShowProgressTips: 0 == e.isShowProgressTips ? 0 : 1
}, e)
},
downloadVoice: function(e) {
M("downloadVoice", {
serverId: e.serverId,
isShowProgressTips: 0 == e.isShowProgressTips ? 0 : 1
}, e)
},
translateVoice: function(e) {
M("translateVoice", {
localId: e.localId,
isShowProgressTips: 0 == e.isShowProgressTips ? 0 : 1
}, e)
},
chooseImage: function(e) {
M("chooseImage", {
scene: "1|2",
count: e.count || 9,
sizeType: e.sizeType || ["original", "compressed"],
sourceType: e.sourceType || ["album", "camera"]
}, (e._complete = function(e) {
if (p) {
var n = e.localIds;
try {
n && (e.localIds = JSON.parse(n))
} catch (e) {}
}
}, e))
},
getLocation: function(e) {},
previewImage: function(e) {
M(c.previewImage, {
current: e.current,
urls: e.urls
}, e)
},
uploadImage: function(e) {
M("uploadImage", {
localId: e.localId,
isShowProgressTips: 0 == e.isShowProgressTips ? 0 : 1
}, e)
},
downloadImage: function(e) {
M("downloadImage", {
serverId: e.serverId,
isShowProgressTips: 0 == e.isShowProgressTips ? 0 : 1
}, e)
},
getLocalImgData: function(e) {
!1 === I ? (I = !0, M("getLocalImgData", {
localId: e.localId
}, (e._complete = function(e) {
if (I = !1, 0 < _.length) {
var n = _.shift();
wx.getLocalImgData(n)
}
}, e))) : _.push(e)
},
getNetworkType: function(e) {
M("getNetworkType", {}, (e._complete = function(e) {
e = function(e) {
var n = e.errMsg;
e.errMsg = "getNetworkType:ok";
var i = e.subtype;
if (delete e.subtype, i) e.networkType = i;
else {
var t = n.indexOf(":"),
o = n.substring(t + 1);
switch (o) {
case "wifi":
case "edge":
case "wwan":
e.networkType = o;
break;
default:
e.errMsg = "getNetworkType:fail"
}
}
return e
}(e)
}, e))
},
openLocation: function(e) {
M("openLocation", {
latitude: e.latitude,
longitude: e.longitude,
name: e.name || "",
address: e.address || "",
scale: e.scale || 28,
infoUrl: e.infoUrl || ""
}, e)
},
getLocation: function(e) {
M(c.getLocation, {
type: (e = e || {}).type || "wgs84"
}, (e._complete = function(e) {
delete e.type
}, e))
},
hideOptionMenu: function(e) {
M("hideOptionMenu", {}, e)
},
showOptionMenu: function(e) {
M("showOptionMenu", {}, e)
},
closeWindow: function(e) {
M("closeWindow", {}, e = e || {})
},
hideMenuItems: function(e) {
M("hideMenuItems", {
menuList: e.menuList
}, e)
},
showMenuItems: function(e) {
M("showMenuItems", {
menuList: e.menuList
}, e)
},
hideAllNonBaseMenuItem: function(e) {
M("hideAllNonBaseMenuItem", {}, e)
},
showAllNonBaseMenuItem: function(e) {
M("showAllNonBaseMenuItem", {}, e)
},
scanQRCode: function(e) {
M("scanQRCode", {
needResult: (e = e || {}).needResult || 0,
scanType: e.scanType || ["qrCode", "barCode"]
}, (e._complete = function(e) {
if (f) {
var n = e.resultStr;
if (n) {
var i = JSON.parse(n);
e.resultStr = i && i.scan_code && i.scan_code.scan_result
}
}
}, e))
},
openAddress: function(e) {
M(c.openAddress, {}, (e._complete = function(e) {
e = function(e) {
return e.postalCode = e.addressPostalCode, delete e
.addressPostalCode, e.provinceName = e.proviceFirstStageName,
delete e.proviceFirstStageName, e.cityName = e
.addressCitySecondStageName, delete e
.addressCitySecondStageName, e.countryName = e
.addressCountiesThirdStageName, delete e
.addressCountiesThirdStageName, e.detailInfo = e
.addressDetailInfo, delete e.addressDetailInfo, e
}(e)
}, e))
},
openProductSpecificView: function(e) {
M(c.openProductSpecificView, {
pid: e.productId,
view_type: e.viewType || 0,
ext_info: e.extInfo
}, e)
},
addCard: function(e) {
for (var n = e.cardList, i = [], t = 0, o = n.length; t < o; ++t) {
var r = n[t],
a = {
card_id: r.cardId,
card_ext: r.cardExt
};
i.push(a)
}
M(c.addCard, {
card_list: i
}, (e._complete = function(e) {
var n = e.card_list;
if (n) {
for (var i = 0, t = (n = JSON.parse(n)).length; i < t; ++i) {
var o = n[i];
o.cardId = o.card_id, o.cardExt = o.card_ext, o.isSuccess = !!o
.is_succ, delete o.card_id, delete o.card_ext, delete o.is_succ
}
e.cardList = n, delete e.card_list
}
}, e))
},
chooseCard: function(e) {
M("chooseCard", {
app_id: v.appId,
location_id: e.shopId || "",
sign_type: e.signType || "SHA1",
card_id: e.cardId || "",
card_type: e.cardType || "",
card_sign: e.cardSign,
time_stamp: e.timestamp + "",
nonce_str: e.nonceStr
}, (e._complete = function(e) {
e.cardList = e.choose_card_info, delete e.choose_card_info
}, e))
},
openCard: function(e) {
for (var n = e.cardList, i = [], t = 0, o = n.length; t < o; ++t) {
var r = n[t],
a = {
card_id: r.cardId,
code: r.code
};
i.push(a)
}
M(c.openCard, {
card_list: i
}, e)
},
consumeAndShareCard: function(e) {
M(c.consumeAndShareCard, {
consumedCardId: e.cardId,
consumedCode: e.code
}, e)
},
chooseWXPay: function(e) {
M(c.chooseWXPay, V(e), e)
},
openEnterpriseRedPacket: function(e) {
M(c.openEnterpriseRedPacket, V(e), e)
},
startSearchBeacons: function(e) {
M(c.startSearchBeacons, {
ticket: e.ticket
}, e)
},
stopSearchBeacons: function(e) {
M(c.stopSearchBeacons, {}, e)
},
onSearchBeacons: function(e) {
P(c.onSearchBeacons, e)
},
openEnterpriseChat: function(e) {
M("openEnterpriseChat", {
useridlist: e.userIds,
chatname: e.groupName
}, e)
},
launchMiniProgram: function(e) {
M("launchMiniProgram", {
targetAppId: e.targetAppId,
path: function(e) {
if ("string" == typeof e && 0 < e.length) {
var n = e.split("?")[0],
i = e.split("?")[1];
return n += ".html", void 0 !== i ? n + "?" + i : n
}
}(e.path),
envVersion: e.envVersion
}, e)
},
openBusinessView: function(e) {
M("openBusinessView", {
businessType: e.businessType,
queryString: e.queryString || "",
envVersion: e.envVersion
}, (e._complete = function(n) {
if (p) {
var e = n.extraData;
if (e) try {
n.extraData = JSON.parse(e)
} catch (e) {
n.extraData = {}
}
}
}, e))
},
miniProgram: {
navigateBack: function(e) {
e = e || {}, O(function() {
M("invokeMiniProgramAPI", {
name: "navigateBack",
arg: {
delta: e.delta || 1
}
}, e)
})
},
navigateTo: function(e) {
O(function() {
M("invokeMiniProgramAPI", {
name: "navigateTo",
arg: {
url: e.url
}
}, e)
})
},
redirectTo: function(e) {
O(function() {
M("invokeMiniProgramAPI", {
name: "redirectTo",
arg: {
url: e.url
}
}, e)
})
},
switchTab: function(e) {
O(function() {
M("invokeMiniProgramAPI", {
name: "switchTab",
arg: {
url: e.url
}
}, e)
})
},
reLaunch: function(e) {
O(function() {
M("invokeMiniProgramAPI", {
name: "reLaunch",
arg: {
url: e.url
}
}, e)
})
},
postMessage: function(e) {
O(function() {
M("invokeMiniProgramAPI", {
name: "postMessage",
arg: e.data || {}
}, e)
})
},
getEnv: function(e) {
O(function() {
e({
miniprogram: "miniprogram" === o.__wxjs_environment
})
})
}
}
},
T = 1,
k = {};
return i.addEventListener("error", function(e) {
if (!p) {
var n = e.target,
i = n.tagName,
t = n.src;
if ("IMG" == i || "VIDEO" == i || "AUDIO" == i || "SOURCE" == i)
if (-1 != t.indexOf("wxlocalresource://")) {
e.preventDefault(), e.stopPropagation();
var o = n["wx-id"];
if (o || (o = T++, n["wx-id"] = o), k[o]) return;
k[o] = !0, wx.ready(function() {
wx.getLocalImgData({
localId: t,
success: function(e) {
n.src = e.localData
}
})
})
}
}
}, !0), i.addEventListener("load", function(e) {
if (!p) {
var n = e.target,
i = n.tagName;
n.src;
if ("IMG" == i || "VIDEO" == i || "AUDIO" == i || "SOURCE" == i) {
var t = n["wx-id"];
t && (k[t] = !1)
}
}
}, !0), e && (o.wx = o.jWeixin = w), w
}
function M(n, e, i) {
o.WeixinJSBridge ? WeixinJSBridge.invoke(n, x(e), function(e) {
A(n, e, i)
}) : B(n, i)
}
function P(n, i, t) {
o.WeixinJSBridge ? WeixinJSBridge.on(n, function(e) {
t && t.trigger && t.trigger(e), A(n, e, i)
}) : B(n, t || i)
}
function x(e) {
return (e = e || {}).appId = v.appId, e.verifyAppId = v.appId, e.verifySignType = "sha1", e
.verifyTimestamp = v.timestamp + "", e.verifyNonceStr = v.nonceStr, e.verifySignature = v.signature, e
}
function V(e) {
return {
timeStamp: e.timestamp + "",
nonceStr: e.nonceStr,
package: e.package,
paySign: e.paySign,
signType: e.signType || "SHA1"
}
}
function A(e, n, i) {
"openEnterpriseChat" != e && "openBusinessView" !== e || (n.errCode = n.err_code), delete n.err_code,
delete n.err_desc, delete n.err_detail;
var t = n.errMsg;
t || (t = n.err_msg, delete n.err_msg, t = function(e, n) {
var i = e,
t = a[i];
t && (i = t);
var o = "ok";
if (n) {
var r = n.indexOf(":");
"confirm" == (o = n.substring(r + 1)) && (o = "ok"), "failed" == o && (o = "fail"), -1 != o
.indexOf("failed_") && (o = o.substring(7)), -1 != o.indexOf("fail_") && (o = o
.substring(5)), "access denied" != (o = (o = o.replace(/_/g, " ")).toLowerCase()) &&
"no permission to execute" != o || (o = "permission denied"), "config" == i &&
"function not exist" == o && (o = "ok"), "" == o && (o = "fail")
}
return n = i + ":" + o
}(e, t), n.errMsg = t), (i = i || {})._complete && (i._complete(n), delete i._complete), t = n.errMsg ||
"", v.debug && !i.isInnerInvoke && alert(JSON.stringify(n));
var o = t.indexOf(":");
switch (t.substring(o + 1)) {
case "ok":
i.success && i.success(n);
break;
case "cancel":
i.cancel && i.cancel(n);
break;
default:
i.fail && i.fail(n)
}
i.complete && i.complete(n)
}
function C(e) {
if (e) {
for (var n = 0, i = e.length; n < i; ++n) {
var t = e[n],
o = c[t];
o && (e[n] = o)
}
return e
}
}
function B(e, n) {
if (!(!v.debug || n && n.isInnerInvoke)) {
var i = a[e];
i && (e = i), n && n._complete && delete n._complete, console.log('"' + e + '",', n || "")
}
}
function L() {
return (new Date).getTime()
}
function O(e) {
l && (o.WeixinJSBridge ? e() : i.addEventListener && i.addEventListener("WeixinJSBridgeReady", e, !1))
}
});

+ 876
- 0
utils/lib/md5.js View File

@ -0,0 +1,876 @@
/**
* [js-md5]{@link https://github.com/emn178/js-md5}
*
* @namespace md5
* @version 0.8.3
* @author Chen, Yi-Cyuan [emn178@gmail.com]
* @copyright Chen, Yi-Cyuan 2014-2023
* @license MIT
*/
(function () {
'use strict';
var INPUT_ERROR = 'input is invalid type';
var FINALIZE_ERROR = 'finalize already called';
var WINDOW = typeof window === 'object';
var root = WINDOW ? window : {};
if (root.JS_MD5_NO_WINDOW) {
WINDOW = false;
}
var WEB_WORKER = !WINDOW && typeof self === 'object';
var NODE_JS = !root.JS_MD5_NO_NODE_JS && typeof process === 'object' && process.versions && process.versions.node;
if (NODE_JS) {
root = global;
} else if (WEB_WORKER) {
root = self;
}
var COMMON_JS = !root.JS_MD5_NO_COMMON_JS && typeof module === 'object' && module.exports;
var AMD = typeof define === 'function' && define.amd;
var ARRAY_BUFFER = !root.JS_MD5_NO_ARRAY_BUFFER && typeof ArrayBuffer !== 'undefined';
var HEX_CHARS = '0123456789abcdef'.split('');
var EXTRA = [128, 32768, 8388608, -2147483648];
var SHIFT = [0, 8, 16, 24];
var OUTPUT_TYPES = ['hex', 'array', 'digest', 'buffer', 'arrayBuffer', 'base64'];
var BASE64_ENCODE_CHAR = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'.split('');
var blocks = [], buffer8;
if (ARRAY_BUFFER) {
var buffer = new ArrayBuffer(68);
buffer8 = new Uint8Array(buffer);
blocks = new Uint32Array(buffer);
}
var isArray = Array.isArray;
if (root.JS_MD5_NO_NODE_JS || !isArray) {
isArray = function (obj) {
return Object.prototype.toString.call(obj) === '[object Array]';
};
}
var isView = ArrayBuffer.isView;
if (ARRAY_BUFFER && (root.JS_MD5_NO_ARRAY_BUFFER_IS_VIEW || !isView)) {
isView = function (obj) {
return typeof obj === 'object' && obj.buffer && obj.buffer.constructor === ArrayBuffer;
};
}
// [message: string, isString: bool]
var formatMessage = function (message) {
var type = typeof message;
if (type === 'string') {
return [message, true];
}
if (type !== 'object' || message === null) {
throw new Error(INPUT_ERROR);
}
if (ARRAY_BUFFER && message.constructor === ArrayBuffer) {
return [new Uint8Array(message), false];
}
if (!isArray(message) && !isView(message)) {
throw new Error(INPUT_ERROR);
}
return [message, false];
}
/**
* @method hex
* @memberof md5
* @description Output hash as hex string
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {String} Hex string
* @example
* md5.hex('The quick brown fox jumps over the lazy dog');
* // equal to
* md5('The quick brown fox jumps over the lazy dog');
*/
/**
* @method digest
* @memberof md5
* @description Output hash as bytes array
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {Array} Bytes array
* @example
* md5.digest('The quick brown fox jumps over the lazy dog');
*/
/**
* @method array
* @memberof md5
* @description Output hash as bytes array
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {Array} Bytes array
* @example
* md5.array('The quick brown fox jumps over the lazy dog');
*/
/**
* @method arrayBuffer
* @memberof md5
* @description Output hash as ArrayBuffer
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {ArrayBuffer} ArrayBuffer
* @example
* md5.arrayBuffer('The quick brown fox jumps over the lazy dog');
*/
/**
* @method buffer
* @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
* @memberof md5
* @description Output hash as ArrayBuffer
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {ArrayBuffer} ArrayBuffer
* @example
* md5.buffer('The quick brown fox jumps over the lazy dog');
*/
/**
* @method base64
* @memberof md5
* @description Output hash as base64 string
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {String} base64 string
* @example
* md5.base64('The quick brown fox jumps over the lazy dog');
*/
var createOutputMethod = function (outputType) {
return function (message) {
return new Md5(true).update(message)[outputType]();
};
};
/**
* @method create
* @memberof md5
* @description Create Md5 object
* @returns {Md5} Md5 object.
* @example
* var hash = md5.create();
*/
/**
* @method update
* @memberof md5
* @description Create and update Md5 object
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {Md5} Md5 object.
* @example
* var hash = md5.update('The quick brown fox jumps over the lazy dog');
* // equal to
* var hash = md5.create();
* hash.update('The quick brown fox jumps over the lazy dog');
*/
var createMethod = function () {
var method = createOutputMethod('hex');
if (NODE_JS) {
method = nodeWrap(method);
}
method.create = function () {
return new Md5();
};
method.update = function (message) {
return method.create().update(message);
};
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
var type = OUTPUT_TYPES[i];
method[type] = createOutputMethod(type);
}
return method;
};
var nodeWrap = function (method) {
var crypto = require('crypto')
var Buffer = require('buffer').Buffer;
var bufferFrom;
if (Buffer.from && !root.JS_MD5_NO_BUFFER_FROM) {
bufferFrom = Buffer.from;
} else {
bufferFrom = function (message) {
return new Buffer(message);
};
}
var nodeMethod = function (message) {
if (typeof message === 'string') {
return crypto.createHash('md5').update(message, 'utf8').digest('hex');
} else {
if (message === null || message === undefined) {
throw new Error(INPUT_ERROR);
} else if (message.constructor === ArrayBuffer) {
message = new Uint8Array(message);
}
}
if (isArray(message) || isView(message) ||
message.constructor === Buffer) {
return crypto.createHash('md5').update(bufferFrom(message)).digest('hex');
} else {
return method(message);
}
};
return nodeMethod;
};
/**
* @namespace md5.hmac
*/
/**
* @method hex
* @memberof md5.hmac
* @description Output hash as hex string
* @param {String|Array|Uint8Array|ArrayBuffer} key key
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {String} Hex string
* @example
* md5.hmac.hex('key', 'The quick brown fox jumps over the lazy dog');
* // equal to
* md5.hmac('key', 'The quick brown fox jumps over the lazy dog');
*/
/**
* @method digest
* @memberof md5.hmac
* @description Output hash as bytes array
* @param {String|Array|Uint8Array|ArrayBuffer} key key
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {Array} Bytes array
* @example
* md5.hmac.digest('key', 'The quick brown fox jumps over the lazy dog');
*/
/**
* @method array
* @memberof md5.hmac
* @description Output hash as bytes array
* @param {String|Array|Uint8Array|ArrayBuffer} key key
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {Array} Bytes array
* @example
* md5.hmac.array('key', 'The quick brown fox jumps over the lazy dog');
*/
/**
* @method arrayBuffer
* @memberof md5.hmac
* @description Output hash as ArrayBuffer
* @param {String|Array|Uint8Array|ArrayBuffer} key key
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {ArrayBuffer} ArrayBuffer
* @example
* md5.hmac.arrayBuffer('key', 'The quick brown fox jumps over the lazy dog');
*/
/**
* @method buffer
* @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
* @memberof md5.hmac
* @description Output hash as ArrayBuffer
* @param {String|Array|Uint8Array|ArrayBuffer} key key
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {ArrayBuffer} ArrayBuffer
* @example
* md5.hmac.buffer('key', 'The quick brown fox jumps over the lazy dog');
*/
/**
* @method base64
* @memberof md5.hmac
* @description Output hash as base64 string
* @param {String|Array|Uint8Array|ArrayBuffer} key key
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {String} base64 string
* @example
* md5.hmac.base64('key', 'The quick brown fox jumps over the lazy dog');
*/
var createHmacOutputMethod = function (outputType) {
return function (key, message) {
return new HmacMd5(key, true).update(message)[outputType]();
};
};
/**
* @method create
* @memberof md5.hmac
* @description Create HmacMd5 object
* @param {String|Array|Uint8Array|ArrayBuffer} key key
* @returns {HmacMd5} HmacMd5 object.
* @example
* var hash = md5.hmac.create('key');
*/
/**
* @method update
* @memberof md5.hmac
* @description Create and update HmacMd5 object
* @param {String|Array|Uint8Array|ArrayBuffer} key key
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {HmacMd5} HmacMd5 object.
* @example
* var hash = md5.hmac.update('key', 'The quick brown fox jumps over the lazy dog');
* // equal to
* var hash = md5.hmac.create('key');
* hash.update('The quick brown fox jumps over the lazy dog');
*/
var createHmacMethod = function () {
var method = createHmacOutputMethod('hex');
method.create = function (key) {
return new HmacMd5(key);
};
method.update = function (key, message) {
return method.create(key).update(message);
};
for (var i = 0; i < OUTPUT_TYPES.length; ++i) {
var type = OUTPUT_TYPES[i];
method[type] = createHmacOutputMethod(type);
}
return method;
};
/**
* Md5 class
* @class Md5
* @description This is internal class.
* @see {@link md5.create}
*/
function Md5(sharedMemory) {
if (sharedMemory) {
blocks[0] = blocks[16] = blocks[1] = blocks[2] = blocks[3] =
blocks[4] = blocks[5] = blocks[6] = blocks[7] =
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
this.blocks = blocks;
this.buffer8 = buffer8;
} else {
if (ARRAY_BUFFER) {
var buffer = new ArrayBuffer(68);
this.buffer8 = new Uint8Array(buffer);
this.blocks = new Uint32Array(buffer);
} else {
this.blocks = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
}
}
this.h0 = this.h1 = this.h2 = this.h3 = this.start = this.bytes = this.hBytes = 0;
this.finalized = this.hashed = false;
this.first = true;
}
/**
* @method update
* @memberof Md5
* @instance
* @description Update hash
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {Md5} Md5 object.
* @see {@link md5.update}
*/
Md5.prototype.update = function (message) {
if (this.finalized) {
throw new Error(FINALIZE_ERROR);
}
var result = formatMessage(message);
message = result[0];
var isString = result[1];
var code, index = 0, i, length = message.length, blocks = this.blocks;
var buffer8 = this.buffer8;
while (index < length) {
if (this.hashed) {
this.hashed = false;
blocks[0] = blocks[16];
blocks[16] = blocks[1] = blocks[2] = blocks[3] =
blocks[4] = blocks[5] = blocks[6] = blocks[7] =
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
}
if (isString) {
if (ARRAY_BUFFER) {
for (i = this.start; index < length && i < 64; ++index) {
code = message.charCodeAt(index);
if (code < 0x80) {
buffer8[i++] = code;
} else if (code < 0x800) {
buffer8[i++] = 0xc0 | (code >>> 6);
buffer8[i++] = 0x80 | (code & 0x3f);
} else if (code < 0xd800 || code >= 0xe000) {
buffer8[i++] = 0xe0 | (code >>> 12);
buffer8[i++] = 0x80 | ((code >>> 6) & 0x3f);
buffer8[i++] = 0x80 | (code & 0x3f);
} else {
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
buffer8[i++] = 0xf0 | (code >>> 18);
buffer8[i++] = 0x80 | ((code >>> 12) & 0x3f);
buffer8[i++] = 0x80 | ((code >>> 6) & 0x3f);
buffer8[i++] = 0x80 | (code & 0x3f);
}
}
} else {
for (i = this.start; index < length && i < 64; ++index) {
code = message.charCodeAt(index);
if (code < 0x80) {
blocks[i >>> 2] |= code << SHIFT[i++ & 3];
} else if (code < 0x800) {
blocks[i >>> 2] |= (0xc0 | (code >>> 6)) << SHIFT[i++ & 3];
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
} else if (code < 0xd800 || code >= 0xe000) {
blocks[i >>> 2] |= (0xe0 | (code >>> 12)) << SHIFT[i++ & 3];
blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
} else {
code = 0x10000 + (((code & 0x3ff) << 10) | (message.charCodeAt(++index) & 0x3ff));
blocks[i >>> 2] |= (0xf0 | (code >>> 18)) << SHIFT[i++ & 3];
blocks[i >>> 2] |= (0x80 | ((code >>> 12) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >>> 2] |= (0x80 | ((code >>> 6) & 0x3f)) << SHIFT[i++ & 3];
blocks[i >>> 2] |= (0x80 | (code & 0x3f)) << SHIFT[i++ & 3];
}
}
}
} else {
if (ARRAY_BUFFER) {
for (i = this.start; index < length && i < 64; ++index) {
buffer8[i++] = message[index];
}
} else {
for (i = this.start; index < length && i < 64; ++index) {
blocks[i >>> 2] |= message[index] << SHIFT[i++ & 3];
}
}
}
this.lastByteIndex = i;
this.bytes += i - this.start;
if (i >= 64) {
this.start = i - 64;
this.hash();
this.hashed = true;
} else {
this.start = i;
}
}
if (this.bytes > 4294967295) {
this.hBytes += this.bytes / 4294967296 << 0;
this.bytes = this.bytes % 4294967296;
}
return this;
};
Md5.prototype.finalize = function () {
if (this.finalized) {
return;
}
this.finalized = true;
var blocks = this.blocks, i = this.lastByteIndex;
blocks[i >>> 2] |= EXTRA[i & 3];
if (i >= 56) {
if (!this.hashed) {
this.hash();
}
blocks[0] = blocks[16];
blocks[16] = blocks[1] = blocks[2] = blocks[3] =
blocks[4] = blocks[5] = blocks[6] = blocks[7] =
blocks[8] = blocks[9] = blocks[10] = blocks[11] =
blocks[12] = blocks[13] = blocks[14] = blocks[15] = 0;
}
blocks[14] = this.bytes << 3;
blocks[15] = this.hBytes << 3 | this.bytes >>> 29;
this.hash();
};
Md5.prototype.hash = function () {
var a, b, c, d, bc, da, blocks = this.blocks;
if (this.first) {
a = blocks[0] - 680876937;
a = (a << 7 | a >>> 25) - 271733879 << 0;
d = (-1732584194 ^ a & 2004318071) + blocks[1] - 117830708;
d = (d << 12 | d >>> 20) + a << 0;
c = (-271733879 ^ (d & (a ^ -271733879))) + blocks[2] - 1126478375;
c = (c << 17 | c >>> 15) + d << 0;
b = (a ^ (c & (d ^ a))) + blocks[3] - 1316259209;
b = (b << 22 | b >>> 10) + c << 0;
} else {
a = this.h0;
b = this.h1;
c = this.h2;
d = this.h3;
a += (d ^ (b & (c ^ d))) + blocks[0] - 680876936;
a = (a << 7 | a >>> 25) + b << 0;
d += (c ^ (a & (b ^ c))) + blocks[1] - 389564586;
d = (d << 12 | d >>> 20) + a << 0;
c += (b ^ (d & (a ^ b))) + blocks[2] + 606105819;
c = (c << 17 | c >>> 15) + d << 0;
b += (a ^ (c & (d ^ a))) + blocks[3] - 1044525330;
b = (b << 22 | b >>> 10) + c << 0;
}
a += (d ^ (b & (c ^ d))) + blocks[4] - 176418897;
a = (a << 7 | a >>> 25) + b << 0;
d += (c ^ (a & (b ^ c))) + blocks[5] + 1200080426;
d = (d << 12 | d >>> 20) + a << 0;
c += (b ^ (d & (a ^ b))) + blocks[6] - 1473231341;
c = (c << 17 | c >>> 15) + d << 0;
b += (a ^ (c & (d ^ a))) + blocks[7] - 45705983;
b = (b << 22 | b >>> 10) + c << 0;
a += (d ^ (b & (c ^ d))) + blocks[8] + 1770035416;
a = (a << 7 | a >>> 25) + b << 0;
d += (c ^ (a & (b ^ c))) + blocks[9] - 1958414417;
d = (d << 12 | d >>> 20) + a << 0;
c += (b ^ (d & (a ^ b))) + blocks[10] - 42063;
c = (c << 17 | c >>> 15) + d << 0;
b += (a ^ (c & (d ^ a))) + blocks[11] - 1990404162;
b = (b << 22 | b >>> 10) + c << 0;
a += (d ^ (b & (c ^ d))) + blocks[12] + 1804603682;
a = (a << 7 | a >>> 25) + b << 0;
d += (c ^ (a & (b ^ c))) + blocks[13] - 40341101;
d = (d << 12 | d >>> 20) + a << 0;
c += (b ^ (d & (a ^ b))) + blocks[14] - 1502002290;
c = (c << 17 | c >>> 15) + d << 0;
b += (a ^ (c & (d ^ a))) + blocks[15] + 1236535329;
b = (b << 22 | b >>> 10) + c << 0;
a += (c ^ (d & (b ^ c))) + blocks[1] - 165796510;
a = (a << 5 | a >>> 27) + b << 0;
d += (b ^ (c & (a ^ b))) + blocks[6] - 1069501632;
d = (d << 9 | d >>> 23) + a << 0;
c += (a ^ (b & (d ^ a))) + blocks[11] + 643717713;
c = (c << 14 | c >>> 18) + d << 0;
b += (d ^ (a & (c ^ d))) + blocks[0] - 373897302;
b = (b << 20 | b >>> 12) + c << 0;
a += (c ^ (d & (b ^ c))) + blocks[5] - 701558691;
a = (a << 5 | a >>> 27) + b << 0;
d += (b ^ (c & (a ^ b))) + blocks[10] + 38016083;
d = (d << 9 | d >>> 23) + a << 0;
c += (a ^ (b & (d ^ a))) + blocks[15] - 660478335;
c = (c << 14 | c >>> 18) + d << 0;
b += (d ^ (a & (c ^ d))) + blocks[4] - 405537848;
b = (b << 20 | b >>> 12) + c << 0;
a += (c ^ (d & (b ^ c))) + blocks[9] + 568446438;
a = (a << 5 | a >>> 27) + b << 0;
d += (b ^ (c & (a ^ b))) + blocks[14] - 1019803690;
d = (d << 9 | d >>> 23) + a << 0;
c += (a ^ (b & (d ^ a))) + blocks[3] - 187363961;
c = (c << 14 | c >>> 18) + d << 0;
b += (d ^ (a & (c ^ d))) + blocks[8] + 1163531501;
b = (b << 20 | b >>> 12) + c << 0;
a += (c ^ (d & (b ^ c))) + blocks[13] - 1444681467;
a = (a << 5 | a >>> 27) + b << 0;
d += (b ^ (c & (a ^ b))) + blocks[2] - 51403784;
d = (d << 9 | d >>> 23) + a << 0;
c += (a ^ (b & (d ^ a))) + blocks[7] + 1735328473;
c = (c << 14 | c >>> 18) + d << 0;
b += (d ^ (a & (c ^ d))) + blocks[12] - 1926607734;
b = (b << 20 | b >>> 12) + c << 0;
bc = b ^ c;
a += (bc ^ d) + blocks[5] - 378558;
a = (a << 4 | a >>> 28) + b << 0;
d += (bc ^ a) + blocks[8] - 2022574463;
d = (d << 11 | d >>> 21) + a << 0;
da = d ^ a;
c += (da ^ b) + blocks[11] + 1839030562;
c = (c << 16 | c >>> 16) + d << 0;
b += (da ^ c) + blocks[14] - 35309556;
b = (b << 23 | b >>> 9) + c << 0;
bc = b ^ c;
a += (bc ^ d) + blocks[1] - 1530992060;
a = (a << 4 | a >>> 28) + b << 0;
d += (bc ^ a) + blocks[4] + 1272893353;
d = (d << 11 | d >>> 21) + a << 0;
da = d ^ a;
c += (da ^ b) + blocks[7] - 155497632;
c = (c << 16 | c >>> 16) + d << 0;
b += (da ^ c) + blocks[10] - 1094730640;
b = (b << 23 | b >>> 9) + c << 0;
bc = b ^ c;
a += (bc ^ d) + blocks[13] + 681279174;
a = (a << 4 | a >>> 28) + b << 0;
d += (bc ^ a) + blocks[0] - 358537222;
d = (d << 11 | d >>> 21) + a << 0;
da = d ^ a;
c += (da ^ b) + blocks[3] - 722521979;
c = (c << 16 | c >>> 16) + d << 0;
b += (da ^ c) + blocks[6] + 76029189;
b = (b << 23 | b >>> 9) + c << 0;
bc = b ^ c;
a += (bc ^ d) + blocks[9] - 640364487;
a = (a << 4 | a >>> 28) + b << 0;
d += (bc ^ a) + blocks[12] - 421815835;
d = (d << 11 | d >>> 21) + a << 0;
da = d ^ a;
c += (da ^ b) + blocks[15] + 530742520;
c = (c << 16 | c >>> 16) + d << 0;
b += (da ^ c) + blocks[2] - 995338651;
b = (b << 23 | b >>> 9) + c << 0;
a += (c ^ (b | ~d)) + blocks[0] - 198630844;
a = (a << 6 | a >>> 26) + b << 0;
d += (b ^ (a | ~c)) + blocks[7] + 1126891415;
d = (d << 10 | d >>> 22) + a << 0;
c += (a ^ (d | ~b)) + blocks[14] - 1416354905;
c = (c << 15 | c >>> 17) + d << 0;
b += (d ^ (c | ~a)) + blocks[5] - 57434055;
b = (b << 21 | b >>> 11) + c << 0;
a += (c ^ (b | ~d)) + blocks[12] + 1700485571;
a = (a << 6 | a >>> 26) + b << 0;
d += (b ^ (a | ~c)) + blocks[3] - 1894986606;
d = (d << 10 | d >>> 22) + a << 0;
c += (a ^ (d | ~b)) + blocks[10] - 1051523;
c = (c << 15 | c >>> 17) + d << 0;
b += (d ^ (c | ~a)) + blocks[1] - 2054922799;
b = (b << 21 | b >>> 11) + c << 0;
a += (c ^ (b | ~d)) + blocks[8] + 1873313359;
a = (a << 6 | a >>> 26) + b << 0;
d += (b ^ (a | ~c)) + blocks[15] - 30611744;
d = (d << 10 | d >>> 22) + a << 0;
c += (a ^ (d | ~b)) + blocks[6] - 1560198380;
c = (c << 15 | c >>> 17) + d << 0;
b += (d ^ (c | ~a)) + blocks[13] + 1309151649;
b = (b << 21 | b >>> 11) + c << 0;
a += (c ^ (b | ~d)) + blocks[4] - 145523070;
a = (a << 6 | a >>> 26) + b << 0;
d += (b ^ (a | ~c)) + blocks[11] - 1120210379;
d = (d << 10 | d >>> 22) + a << 0;
c += (a ^ (d | ~b)) + blocks[2] + 718787259;
c = (c << 15 | c >>> 17) + d << 0;
b += (d ^ (c | ~a)) + blocks[9] - 343485551;
b = (b << 21 | b >>> 11) + c << 0;
if (this.first) {
this.h0 = a + 1732584193 << 0;
this.h1 = b - 271733879 << 0;
this.h2 = c - 1732584194 << 0;
this.h3 = d + 271733878 << 0;
this.first = false;
} else {
this.h0 = this.h0 + a << 0;
this.h1 = this.h1 + b << 0;
this.h2 = this.h2 + c << 0;
this.h3 = this.h3 + d << 0;
}
};
/**
* @method hex
* @memberof Md5
* @instance
* @description Output hash as hex string
* @returns {String} Hex string
* @see {@link md5.hex}
* @example
* hash.hex();
*/
Md5.prototype.hex = function () {
this.finalize();
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
return HEX_CHARS[(h0 >>> 4) & 0x0F] + HEX_CHARS[h0 & 0x0F] +
HEX_CHARS[(h0 >>> 12) & 0x0F] + HEX_CHARS[(h0 >>> 8) & 0x0F] +
HEX_CHARS[(h0 >>> 20) & 0x0F] + HEX_CHARS[(h0 >>> 16) & 0x0F] +
HEX_CHARS[(h0 >>> 28) & 0x0F] + HEX_CHARS[(h0 >>> 24) & 0x0F] +
HEX_CHARS[(h1 >>> 4) & 0x0F] + HEX_CHARS[h1 & 0x0F] +
HEX_CHARS[(h1 >>> 12) & 0x0F] + HEX_CHARS[(h1 >>> 8) & 0x0F] +
HEX_CHARS[(h1 >>> 20) & 0x0F] + HEX_CHARS[(h1 >>> 16) & 0x0F] +
HEX_CHARS[(h1 >>> 28) & 0x0F] + HEX_CHARS[(h1 >>> 24) & 0x0F] +
HEX_CHARS[(h2 >>> 4) & 0x0F] + HEX_CHARS[h2 & 0x0F] +
HEX_CHARS[(h2 >>> 12) & 0x0F] + HEX_CHARS[(h2 >>> 8) & 0x0F] +
HEX_CHARS[(h2 >>> 20) & 0x0F] + HEX_CHARS[(h2 >>> 16) & 0x0F] +
HEX_CHARS[(h2 >>> 28) & 0x0F] + HEX_CHARS[(h2 >>> 24) & 0x0F] +
HEX_CHARS[(h3 >>> 4) & 0x0F] + HEX_CHARS[h3 & 0x0F] +
HEX_CHARS[(h3 >>> 12) & 0x0F] + HEX_CHARS[(h3 >>> 8) & 0x0F] +
HEX_CHARS[(h3 >>> 20) & 0x0F] + HEX_CHARS[(h3 >>> 16) & 0x0F] +
HEX_CHARS[(h3 >>> 28) & 0x0F] + HEX_CHARS[(h3 >>> 24) & 0x0F];
};
/**
* @method toString
* @memberof Md5
* @instance
* @description Output hash as hex string
* @returns {String} Hex string
* @see {@link md5.hex}
* @example
* hash.toString();
*/
Md5.prototype.toString = Md5.prototype.hex;
/**
* @method digest
* @memberof Md5
* @instance
* @description Output hash as bytes array
* @returns {Array} Bytes array
* @see {@link md5.digest}
* @example
* hash.digest();
*/
Md5.prototype.digest = function () {
this.finalize();
var h0 = this.h0, h1 = this.h1, h2 = this.h2, h3 = this.h3;
return [
h0 & 0xFF, (h0 >>> 8) & 0xFF, (h0 >>> 16) & 0xFF, (h0 >>> 24) & 0xFF,
h1 & 0xFF, (h1 >>> 8) & 0xFF, (h1 >>> 16) & 0xFF, (h1 >>> 24) & 0xFF,
h2 & 0xFF, (h2 >>> 8) & 0xFF, (h2 >>> 16) & 0xFF, (h2 >>> 24) & 0xFF,
h3 & 0xFF, (h3 >>> 8) & 0xFF, (h3 >>> 16) & 0xFF, (h3 >>> 24) & 0xFF
];
};
/**
* @method array
* @memberof Md5
* @instance
* @description Output hash as bytes array
* @returns {Array} Bytes array
* @see {@link md5.array}
* @example
* hash.array();
*/
Md5.prototype.array = Md5.prototype.digest;
/**
* @method arrayBuffer
* @memberof Md5
* @instance
* @description Output hash as ArrayBuffer
* @returns {ArrayBuffer} ArrayBuffer
* @see {@link md5.arrayBuffer}
* @example
* hash.arrayBuffer();
*/
Md5.prototype.arrayBuffer = function () {
this.finalize();
var buffer = new ArrayBuffer(16);
var blocks = new Uint32Array(buffer);
blocks[0] = this.h0;
blocks[1] = this.h1;
blocks[2] = this.h2;
blocks[3] = this.h3;
return buffer;
};
/**
* @method buffer
* @deprecated This maybe confuse with Buffer in node.js. Please use arrayBuffer instead.
* @memberof Md5
* @instance
* @description Output hash as ArrayBuffer
* @returns {ArrayBuffer} ArrayBuffer
* @see {@link md5.buffer}
* @example
* hash.buffer();
*/
Md5.prototype.buffer = Md5.prototype.arrayBuffer;
/**
* @method base64
* @memberof Md5
* @instance
* @description Output hash as base64 string
* @returns {String} base64 string
* @see {@link md5.base64}
* @example
* hash.base64();
*/
Md5.prototype.base64 = function () {
var v1, v2, v3, base64Str = '', bytes = this.array();
for (var i = 0; i < 15;) {
v1 = bytes[i++];
v2 = bytes[i++];
v3 = bytes[i++];
base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +
BASE64_ENCODE_CHAR[(v1 << 4 | v2 >>> 4) & 63] +
BASE64_ENCODE_CHAR[(v2 << 2 | v3 >>> 6) & 63] +
BASE64_ENCODE_CHAR[v3 & 63];
}
v1 = bytes[i];
base64Str += BASE64_ENCODE_CHAR[v1 >>> 2] +
BASE64_ENCODE_CHAR[(v1 << 4) & 63] +
'==';
return base64Str;
};
/**
* HmacMd5 class
* @class HmacMd5
* @extends Md5
* @description This is internal class.
* @see {@link md5.hmac.create}
*/
function HmacMd5(key, sharedMemory) {
var i, result = formatMessage(key);
key = result[0];
if (result[1]) {
var bytes = [], length = key.length, index = 0, code;
for (i = 0; i < length; ++i) {
code = key.charCodeAt(i);
if (code < 0x80) {
bytes[index++] = code;
} else if (code < 0x800) {
bytes[index++] = (0xc0 | (code >>> 6));
bytes[index++] = (0x80 | (code & 0x3f));
} else if (code < 0xd800 || code >= 0xe000) {
bytes[index++] = (0xe0 | (code >>> 12));
bytes[index++] = (0x80 | ((code >>> 6) & 0x3f));
bytes[index++] = (0x80 | (code & 0x3f));
} else {
code = 0x10000 + (((code & 0x3ff) << 10) | (key.charCodeAt(++i) & 0x3ff));
bytes[index++] = (0xf0 | (code >>> 18));
bytes[index++] = (0x80 | ((code >>> 12) & 0x3f));
bytes[index++] = (0x80 | ((code >>> 6) & 0x3f));
bytes[index++] = (0x80 | (code & 0x3f));
}
}
key = bytes;
}
if (key.length > 64) {
key = (new Md5(true)).update(key).array();
}
var oKeyPad = [], iKeyPad = [];
for (i = 0; i < 64; ++i) {
var b = key[i] || 0;
oKeyPad[i] = 0x5c ^ b;
iKeyPad[i] = 0x36 ^ b;
}
Md5.call(this, sharedMemory);
this.update(iKeyPad);
this.oKeyPad = oKeyPad;
this.inner = true;
this.sharedMemory = sharedMemory;
}
HmacMd5.prototype = new Md5();
HmacMd5.prototype.finalize = function () {
Md5.prototype.finalize.call(this);
if (this.inner) {
this.inner = false;
var innerHash = this.array();
Md5.call(this, this.sharedMemory);
this.update(this.oKeyPad);
this.update(innerHash);
Md5.prototype.finalize.call(this);
}
};
var exports = createMethod();
exports.md5 = exports;
exports.md5.hmac = createHmacMethod();
if (COMMON_JS) {
module.exports = exports;
} else {
/**
* @method md5
* @description Md5 hash function, export to global in browsers.
* @param {String|Array|Uint8Array|ArrayBuffer} message message to hash
* @returns {String} md5 hashes
* @example
* md5(''); // d41d8cd98f00b204e9800998ecf8427e
* md5('The quick brown fox jumps over the lazy dog'); // 9e107d9d372bb6826bd81d3542a419d6
* md5('The quick brown fox jumps over the lazy dog.'); // e4d909c290d0fb1ca068ffaddf22cbd0
*
* // It also supports UTF-8 encoding
* md5('中文'); // a7bac2239fcdcb3a067903d8077c4a07
*
* // It also supports byte `Array`, `Uint8Array`, `ArrayBuffer`
* md5([]); // d41d8cd98f00b204e9800998ecf8427e
* md5(new Uint8Array([])); // d41d8cd98f00b204e9800998ecf8427e
*/
root.md5 = exports;
if (AMD) {
define(function () {
return exports;
});
}
}
})();

+ 47
- 0
utils/pay.js View File

@ -0,0 +1,47 @@
// #ifdef H5
import jWeixin from './lib/jweixin-module.js'
// #endif
/**
* 调用微信支付
* @param {Object} res - 支付参数对象包含appIdtimeStampnonceStr等必要信息
* @returns {Promise} - 返回Promise对象resolve表示支付成功reject表示支付失败
*/
export function wxPay(res) {
return new Promise((resolve, reject) => {
// 配置微信JSSDK
// jWeixin.config({
// debug: false,
// appId: res.result.appId, //必填,公众号的唯一标识
// jsApiList: ['chooseWXPay'] //必填,需要使用的JS接口列表
// });
// JSSDK配置成功后的回调
jWeixin.ready(function() {
// 调用微信支付接口
jWeixin.chooseWXPay({
appId: res.result.appId,
timestamp: res.result.timeStamp, // 支付签名时间戳
nonceStr: res.result.nonceStr, // 支付签名随机串
package: res.result.packageValue, // 统一支付接口返回的prepay_id参数值
signType: res.result.signType, // 签名类型,默认为MD5
paySign: res.result.paySign, // 支付签名
success: function(result) {
resolve(result);
},
fail: function(error) {
reject(error);
},
cancel: function(error) {
reject({ type: 'cancel', ...error });
}
});
});
// JSSDK配置失败处理
jWeixin.error(function(error) {
reject({ type: 'config_error', ...error });
});
});
}

+ 87
- 0
utils/share.js View File

@ -0,0 +1,87 @@
import login from '@/api/modules/login'
// import config from "../config.js"
import jWeixin from './lib/jweixin-module.js'
import Vue from 'vue'
function share() { //微信分享
//获取签名
let data = {
// location.href.split('#')[0])
// url: Vue.prototype.$config.redirect + '/#/'
url: location.href.split('#')[0]
}
login.getSignPackage(data, res => {
if (res.code == 200) {
let {
appId,
nonceStr,
signature,
timestamp
} = res.result
jWeixin.config({
debug: false,
appId: appId,
nonceStr: nonceStr,
signature: signature,
timestamp: timestamp,
jsApiList: [
'updateTimelineShareData',
'updateAppMessageShareData',
'onMenuShareWeibo',
'getLocation',
'chooseWXPay',
'requestMerchantTransfer',
'checkJsApi',
'scanQRCode',
],
success: function() {
console.log('配置成功');
}
});
jWeixin.ready(function() {
// 微信分享的数据
var shareData = {
"link": addQueryParams(data.url),
"desc": "四零语境",
"title": "四零语境,温柔呵护每一刻!",
imgUrl : location.href.split('#')[0] + '/static/share/logo.png',
success: function() {
//分享成功可以做相应的数据处理
console.log('注册分享成功');
// uni.showToast({
// mask: true,
// duration: 1000,
// title: '注册分享成功',
// });
}
};
//分享微信朋友圈内容设置
jWeixin.updateTimelineShareData(shareData);
//分享给朋友内容设置
jWeixin.updateAppMessageShareData(shareData);
//分享到微博内容设置
jWeixin.onMenuShareWeibo(shareData);
});
jWeixin.error(function(err){
console.error(err);
// config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。
})
}
})
}
function addQueryParams(url) {
if (url) {
//获取用户id
let userInfo = localStorage.getItem('userInfo') ? JSON.parse(localStorage.getItem('userInfo')) : null
if(userInfo){
url += `?vid=${userInfo.id}`
}
}
return url
}
export default share

Loading…
Cancel
Save