java-mall-app/helpers/jweixinShare.js
2024-11-01 16:35:40 +08:00

130 lines
3.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
微信支付方法(uni-app h5)适用
获取微信加签信息
@param{data}:获取的微信加签
@param{res}:成功回调
@param{fail}:失败回调
@warn:因为package为严格模式下的保留字不能用作变量.
@use
wPay({
appId,
timeStamp,
nonceStr,
signature,
package,
paySign
},res=>{
console.log('调用成功!');
},fail=>{
console.log('调用失败!');
})
*/
import __config from '../config/config'
import wx from './jweixin'
function initWxShareReady(data, $title, $desc, $link, $img_url, url)
{
let [appId, timestamp, nonceStr, signature, packages, paySign] = [data.appId, data.timestamp, data.nonceStr, data.signature,
data.package, data.paySign
];
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来若要查看传入的参数可以在pc端打开参数信息会通过log打出仅在pc端时才会打印。
appId, // 必填,公众号的唯一标识
timestamp, // 必填,生成签名的时间戳
nonceStr, // 必填,生成签名的随机串
signature, // 必填签名见附录1
href: $link,
jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage']
});
wx.ready(function () {
$link = url;
if($img_url.indexOf("https") == 0 || $img_url.indexOf("http"))
{
$img_url = $img_url;
}
else
{
if(__config.HTTPS)
{
$img_url = "http:" + $img_url;
}
else
{
$img_url = "https:" + $img_url;
}
}
wx.onMenuShareTimeline({
title: $title, //分享标题
desc: $desc, //分享描述
link: $link, //分享链接
imgUrl: $img_url, //分享图标
success: function () {
},
cancel: function () {
}
});
wx.onMenuShareAppMessage({
title: $title, //分享标题
desc: $desc, //分享描述
link: $link, //分享链接
imgUrl: $img_url, //分享图标
type: 'link',
dataUrl: '',
success: function () {
},
cancel: function () {
}
});
wx.onMenuShareQQ({
title: $title, //分享标题
desc: $desc, //分享描述
link: $link, //分享链接
imgUrl: $img_url, //分享图标
success: function () {
},
cancel: function () {
}
});
wx.onMenuShareWeibo({
title: $title, //分享标题
desc: $desc, //分享描述
link: $link, //分享链接
imgUrl: $img_url, //分享图标
success: function () {
},
cancel: function () {
}
});
wx.onMenuShareQZone({
title: $title, //分享标题
desc: $desc, //分享描述
link: $link, //分享链接
imgUrl: $img_url, //分享图标
success: function () {
},
cancel: function () {
}
});
});
wx.error(function(res) {
// config信息验证失败会执行error函数如签名过期导致验证失败具体错误信息可以打开config的debug模式查看也可以在返回的res参数中查看对于SPA可以在这里更新签名。
/*alert("config信息验证失败");*/
});
}
export default initWxShareReady;