update
This commit is contained in:
+37
-45
@@ -3,52 +3,44 @@ import util from "@/util";
|
||||
|
||||
function signToWechat(config, shareConfig) {
|
||||
if (!wx) {
|
||||
console.warn('请安装微信网页JS-SDK, url: https://res2.wx.qq.com/open/js/jweixin-1.6.0.js');
|
||||
console.warn("请安装微信网页JS-SDK, url: https://res2.wx.qq.com/open/js/jweixin-1.6.0.js");
|
||||
}
|
||||
const defaultConfig = {
|
||||
...config,
|
||||
debug: false,
|
||||
jsApiList: [
|
||||
'onMenuShareTimeline',
|
||||
'onMenuShareAppMessage',
|
||||
'scanQRCode',
|
||||
'getLocation',
|
||||
'openLocation',
|
||||
'updateAppMessageShareData',
|
||||
'updateTimelineShareData'
|
||||
],
|
||||
jsApiList: ["onMenuShareTimeline", "onMenuShareAppMessage", "scanQRCode", "getLocation", "openLocation", "updateAppMessageShareData", "updateTimelineShareData"],
|
||||
};
|
||||
console.log('sign', wx);
|
||||
wx.config(defaultConfig);
|
||||
wx.ready(function() {
|
||||
|
||||
console.log('wechat sdk config success');
|
||||
wx.ready(function () {
|
||||
console.log("wechat sdk config success");
|
||||
wechatInstance = wx;
|
||||
|
||||
wx.onMenuShareAppMessage({
|
||||
title: shareConfig.title,
|
||||
desc: shareConfig.desc,
|
||||
link: util.addExternalParamsToQuery(shareConfig.link, 'no_login', 1),
|
||||
link: util.addExternalParamsToQuery(shareConfig.link, "no_login", 1),
|
||||
imgUrl: shareConfig.imgUrl,
|
||||
complete: res => {
|
||||
shareConfig.callback && shareConfig.callback({
|
||||
key: 'updateAppMessageShareData',
|
||||
...res
|
||||
});
|
||||
}
|
||||
complete: (res) => {
|
||||
shareConfig.callback &&
|
||||
shareConfig.callback({
|
||||
key: "updateAppMessageShareData",
|
||||
...res,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
// // 分享朋友圈
|
||||
wx.onMenuShareTimeline({
|
||||
title: shareConfig.title,
|
||||
link: util.addExternalParamsToQuery(shareConfig.link, 'no_login', 1),
|
||||
link: util.addExternalParamsToQuery(shareConfig.link, "no_login", 1),
|
||||
imgUrl: shareConfig.imgUrl,
|
||||
complete: res => {
|
||||
shareConfig.callback && shareConfig.callback({
|
||||
key: 'updateTimelineShareData',
|
||||
...res
|
||||
});
|
||||
}
|
||||
complete: (res) => {
|
||||
shareConfig.callback &&
|
||||
shareConfig.callback({
|
||||
key: "updateTimelineShareData",
|
||||
...res,
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
// wx.updateAppMessageShareData({
|
||||
@@ -81,9 +73,9 @@ function signToWechat(config, shareConfig) {
|
||||
function getLocation() {
|
||||
return new Promise((resolve, reject) => {
|
||||
wechatInstance.getLocation({
|
||||
type: 'wgs84',
|
||||
success: res => {
|
||||
if(res.errMsg === 'getLocation:ok'){
|
||||
type: "wgs84",
|
||||
success: (res) => {
|
||||
if (res.errMsg === "getLocation:ok") {
|
||||
resolve(res);
|
||||
} else {
|
||||
reject();
|
||||
@@ -91,26 +83,26 @@ function getLocation() {
|
||||
},
|
||||
error: () => {
|
||||
reject();
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function requestPayment(paymentConfig) {
|
||||
return new Promise(resolve => {
|
||||
return new Promise((resolve) => {
|
||||
wechatInstance.chooseWXPay({
|
||||
timestamp: paymentConfig.timestamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
|
||||
nonceStr: paymentConfig.nonceStr, // 支付签名随机串,不长于 32 位
|
||||
package: paymentConfig.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)
|
||||
signType: paymentConfig.signType, // 微信支付V3的传入RSA,微信支付V2的传入格式与V2统一下单的签名格式保持一致
|
||||
paySign: paymentConfig.paySign, // 支付签名
|
||||
success: function(res) {
|
||||
success: function (res) {
|
||||
// 支付成功后的回调函数
|
||||
resolve(res);
|
||||
},
|
||||
fail(res) {
|
||||
alert(JSON.stringify(res));
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -120,40 +112,40 @@ function openLocation(config) {
|
||||
}
|
||||
|
||||
// 分享给朋友
|
||||
function updateAppMessageShareData(title = '', desc = '', link = '', imgUrl = '') {
|
||||
function updateAppMessageShareData(title = "", desc = "", link = "", imgUrl = "") {
|
||||
return new Promise((resolve) => {
|
||||
wechatInstance.updateAppMessageShareData({
|
||||
title,
|
||||
desc,
|
||||
link,
|
||||
imgUrl,
|
||||
complete: res => {
|
||||
complete: (res) => {
|
||||
resolve(res);
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// 分享到朋友圈
|
||||
function updateTimelineShareData(title = '', desc = '', link = '', imgUrl = '') {
|
||||
function updateTimelineShareData(title = "", desc = "", link = "", imgUrl = "") {
|
||||
return new Promise((resolve) => {
|
||||
wechatInstance.updateTimelineShareData({
|
||||
title,
|
||||
desc,
|
||||
link,
|
||||
imgUrl,
|
||||
complete: res => {
|
||||
complete: (res) => {
|
||||
resolve(res);
|
||||
}
|
||||
},
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function previewImage(current, urls){
|
||||
function previewImage(current, urls) {
|
||||
wechatInstance.previewImage({
|
||||
current, urls
|
||||
})
|
||||
current,
|
||||
urls,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
export { signToWechat, getLocation, requestPayment, openLocation, updateAppMessageShareData, updateTimelineShareData, previewImage };
|
||||
|
||||
Reference in New Issue
Block a user