|
|
@ -1,4 +1,7 @@ |
|
|
|
var jweixin = require('jweixin-module') |
|
|
|
var jweixin = require('jweixin-module') |
|
|
|
|
|
|
|
const userId = uni.getStorageSync('userId'); |
|
|
|
|
|
|
|
console.log(userId,'userId') |
|
|
|
|
|
|
|
import HttpRequest from '../common/httpRequest' |
|
|
|
export default { |
|
|
|
export default { |
|
|
|
//判断是否在微信中
|
|
|
|
//判断是否在微信中
|
|
|
|
isWechat: function () { |
|
|
|
isWechat: function () { |
|
|
@ -13,17 +16,8 @@ export default { |
|
|
|
}, |
|
|
|
}, |
|
|
|
//初始化sdk配置
|
|
|
|
//初始化sdk配置
|
|
|
|
initJssdkShare: function (callback, url) { |
|
|
|
initJssdkShare: function (callback, url) { |
|
|
|
uni.request({ |
|
|
|
HttpRequest.getT('/appLogin/jsapiInit',{url: url}).then((result)=>{ |
|
|
|
url: 'http://licai.youma.me/index/wechat/', |
|
|
|
if(result.code == 0){ |
|
|
|
method: 'GET', |
|
|
|
|
|
|
|
data: { |
|
|
|
|
|
|
|
url: 'http://licaifrot.youma.me/' |
|
|
|
|
|
|
|
}, //这里不是统一的,看你们后端
|
|
|
|
|
|
|
|
success: (res) => { |
|
|
|
|
|
|
|
console.log(res) |
|
|
|
|
|
|
|
if (res.statusCode == 200) { |
|
|
|
|
|
|
|
let result = res.data.Data |
|
|
|
|
|
|
|
console.log(result) |
|
|
|
|
|
|
|
jweixin.config({ |
|
|
|
jweixin.config({ |
|
|
|
debug: false, |
|
|
|
debug: false, |
|
|
|
appId: result.appId, |
|
|
|
appId: result.appId, |
|
|
@ -34,19 +28,16 @@ export default { |
|
|
|
'chooseWXPay', |
|
|
|
'chooseWXPay', |
|
|
|
'checkJsApi', |
|
|
|
'checkJsApi', |
|
|
|
'updateTimelineShareData', |
|
|
|
'updateTimelineShareData', |
|
|
|
'updateAppMessageShareData' |
|
|
|
'updateAppMessageShareData', |
|
|
|
|
|
|
|
'getLocation' |
|
|
|
] |
|
|
|
] |
|
|
|
}); |
|
|
|
}); |
|
|
|
//配置完成后,再执行分享等功能
|
|
|
|
|
|
|
|
if (callback) { |
|
|
|
if (callback) { |
|
|
|
callback(result); |
|
|
|
callback(result); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}); |
|
|
|
|
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
//在需要自定义分享的页面中调用
|
|
|
|
|
|
|
|
share: function (data, url) { |
|
|
|
share: function (data, url) { |
|
|
|
url = url ? url : window.location.href; |
|
|
|
url = url ? url : window.location.href; |
|
|
|
console.log("url:" + url) |
|
|
|
console.log("url:" + url) |
|
|
@ -75,8 +66,74 @@ export default { |
|
|
|
//分享到朋友圈接口
|
|
|
|
//分享到朋友圈接口
|
|
|
|
// jweixin.updateTimelineShareData(shareData);
|
|
|
|
// jweixin.updateTimelineShareData(shareData);
|
|
|
|
}); |
|
|
|
}); |
|
|
|
}, url); |
|
|
|
}, 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) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|