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.
139 lines
3.5 KiB
139 lines
3.5 KiB
var jweixin = require('jweixin-module') |
|
const userId = uni.getStorageSync('userId'); |
|
console.log(userId,'userId') |
|
import HttpRequest from '../common/httpRequest' |
|
export default { |
|
//判断是否在微信中 |
|
isWechat: function () { |
|
var ua = window.navigator.userAgent.toLowerCase(); |
|
if (ua.match(/micromessenger/i) == 'micromessenger') { |
|
// console.log(‘是微信客户端‘) |
|
return true; |
|
} else { |
|
// console.log(‘不是微信客户端‘) |
|
return false; |
|
} |
|
}, |
|
//初始化sdk配置 |
|
initJssdkShare: function (callback, url) { |
|
HttpRequest.getT('/appLogin/jsapiInit',{url: url}).then((result)=>{ |
|
if(result.code == 0){ |
|
jweixin.config({ |
|
debug: false, |
|
appId: result.appId, |
|
timestamp: result.timestamp, |
|
nonceStr: result.nonceStr, |
|
signature: result.signature, |
|
jsApiList: [ |
|
'chooseWXPay', |
|
'checkJsApi', |
|
'updateTimelineShareData', |
|
'updateAppMessageShareData', |
|
'getLocation' |
|
] |
|
}); |
|
if (callback) { |
|
callback(result); |
|
} |
|
} |
|
}) |
|
}, |
|
share: function (data, url) { |
|
url = url ? url : window.location.href; |
|
console.log("url:" + url) |
|
if (!this.isWechat()) { |
|
uni.showToast({ |
|
title: '不在微信客户端', |
|
icon: 'none' |
|
}) |
|
return; |
|
} |
|
//每次都需要重新初始化配置,才可以进行分享 |
|
this.initJssdkShare(function (signData) { |
|
jweixin.ready(function () { |
|
var shareData = { |
|
title: data && data.title ? data.title : signData.site_name, |
|
desc: data && data.desc ? data.desc : signData.site_description, |
|
link: url, |
|
imgUrl: data && data.img ? data.img : signData.site_logo, |
|
success: function (res) { |
|
// 分享后的一些操作,比如分享统计等等 |
|
}, |
|
cancel: function (res) {} |
|
}; |
|
//分享给朋友接口 |
|
jweixin.updateAppMessageShareData(shareData); |
|
//分享到朋友圈接口 |
|
// jweixin.updateTimelineShareData(shareData); |
|
}); |
|
}, url) |
|
}, |
|
wxChatWebPay: function (url) { |
|
if (!this.isWechat()) { |
|
uni.showToast({ |
|
title: '不在微信客户端', |
|
icon: 'none' |
|
}) |
|
return; |
|
} |
|
return new Promise((resolve,reject)=>{ |
|
//每次都需要重新初始化配置 |
|
this.initJssdkShare(function () { |
|
jweixin.ready(function () { |
|
HttpRequest.postT('/api/order/wxPayMember?userId=' + userId + '&type=3').then((orderInfo)=>{ |
|
jweixin.chooseWXPay({ |
|
nonceStr: orderInfo.noncestr, |
|
timestamp: orderInfo.timestamp, |
|
package: orderInfo.package, |
|
signType: orderInfo.signType, |
|
paySign: orderInfo.sign, |
|
success: (res) => { |
|
console.log('支付成功') |
|
resolve(res) |
|
}, |
|
fail: (res)=> { |
|
reject(res) |
|
console.log('支付失败') |
|
}, |
|
cancel: (res)=> { |
|
resolve(res) |
|
console.log('取消支付') |
|
} |
|
}) |
|
}) |
|
|
|
}); |
|
},url) |
|
}) |
|
}, |
|
wxGetLocation: function(url){ |
|
return new Promise((resolve,reject)=>{ |
|
if (!this.isWechat()) { |
|
uni.showModal({ |
|
title: '提示!', |
|
content: '请在微信客户端内打开', |
|
showCancel: false |
|
}) |
|
uni.hideLoading() |
|
return |
|
reject(res) |
|
} |
|
//每次都需要重新初始化配置 |
|
this.initJssdkShare(function () { |
|
jweixin.ready(function () { |
|
jweixin.getLocation({ |
|
type: 'wgs84', |
|
success: function (res) { |
|
console.log('jssdk获取的位置:',res.longitude,res.latitude) |
|
resolve(res) |
|
}, |
|
cancel: function (res) { |
|
reject(res) |
|
alert('您已禁止获取位置信息') |
|
} |
|
}); |
|
}); |
|
},url) |
|
}) |
|
} |
|
}
|
|
|