Commit d3083f70 authored by 王建威's avatar 王建威

小程序支付

parent a1e87df7
...@@ -48,6 +48,44 @@ ...@@ -48,6 +48,44 @@
$draggable.on('staticClick', function( event, pointer ) { $draggable.on('staticClick', function( event, pointer ) {
$('#qidian_dom').click(); $('#qidian_dom').click();
}) })
const { origin } = window.location;
let url = '';
// 测试环境
if(origin.indexOf('local') > -1 || origin.indexOf('test') > -1){
if(origin.indexOf('test') > -1){
url = `${origin}/mobile/index.php?`;
}else{
url = 'https://test.pet-dbc.cn/mobile/index.php?';
}
}else if(origin.indexOf('jingxiang') > -1){
url = 'https://jingxiang.pet-dbc.cn/mobile/index.php?';
}else{
url = 'https://shop.pet-dbc.cn/mobile/index.php?';
}
var search = window.location.href.split('?');
if(search[1]) {
var arr = search[1].split('&');
arr.every((item, index) => {
var kv = item.split('=');
if(kv[0] === 'openId') {
localStorage.openId = kv[1];
$.ajax({
url: url + 'app=weixin&act=autoLogin',
type: 'get',
data: {
openid: kv[1]
},
dataType: 'json',
success: function(res) {
alert(JSON.stringify(res))
}
})
}
if(kv[0] === 'inionid') {
localStorage.unionid = kv[1];
}
});
}
</script> </script>
<!-- built files will be auto injected --> <!-- built files will be auto injected -->
</body> </body>
......
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
"mode": "history", "mode": "history",
"base": "/uni" "base": "/uni"
}, },
"publicPath": "https://dbc-static.oss-cn-beijing.aliyuncs.com/dbc-shop/uni/mirror/1.0.13/", "publicPath": "https://dbc-static.oss-cn-beijing.aliyuncs.com/dbc-shop/uni/test/1.0.13/",
"optimization": { "optimization": {
"treeShaking": { "treeShaking": {
"enable": true "enable": true
......
{ {
"name": "shop_mobile_uni", "name": "shop_mobile_uni",
"version": "1.0.13", "version": "1.0.14",
"description": "谛宝多多商城", "description": "谛宝多多商城",
"scripts": { "scripts": {
"test": "echo \"Error: no test specified\" && exit 1", "test": "echo \"Error: no test specified\" && exit 1",
......
...@@ -78,65 +78,72 @@ ...@@ -78,65 +78,72 @@
},2000); },2000);
return; return;
} }
WeixinJSBridge.invoke( wx.miniProgram.getEnv(function (res) {
'getBrandWCPayRequest', { if(res.miniprogram){
"appId": res.app_id, //公众号名称,由商户传入 var path = '/pages/pay/index?payParam='+encodeURIComponent(JSON.stringify(res))+'&type=uni';
"timeStamp": res.timeStamp, //时间戳,自1970年以来的秒数 wx.miniProgram.navigateTo({url: path});
"nonceStr": res.nonce_str, //随机串 } else {
"package": res.package, WeixinJSBridge.invoke(
"signType": res.sign_type, //微信签名方式: 'getBrandWCPayRequest', {
"paySign": res.pay_sign //微信签名 "appId": res.app_id, //公众号名称,由商户传入
}, "timeStamp": res.timeStamp, //时间戳,自1970年以来的秒数
function (res) { "nonceStr": res.nonce_str, //随机串
WeixinJSBridge.log(res.err_msg); "package": res.package,
const url = window.location.origin; "signType": res.sign_type, //微信签名方式:
if (res.err_msg === "get_brand_wcpay_request:ok") { "paySign": res.pay_sign //微信签名
uni.navigateTo({ },
url: '/pages/payresult/payresult' function (res) {
}) WeixinJSBridge.log(res.err_msg);
} else if (res.err_msg === "get_brand_wcpay_request:cancel") { const url = window.location.origin;
uni.showToast({ if (res.err_msg === "get_brand_wcpay_request:ok") {
title: '已取消支付,请重新支付', uni.navigateTo({
duration: 2000, url: '/pages/payresult/payresult'
icon: 'none' })
}); } else if (res.err_msg === "get_brand_wcpay_request:cancel") {
setTimeout(() => { uni.showToast({
history.back(); title: '已取消支付,请重新支付',
},2000); duration: 2000,
} else if (res.err_msg === "get_brand_wcpay_request:fail") { icon: 'none'
// Toast.fail('支付失败', 3); });
uni.showToast({ setTimeout(() => {
title: '支付失败,请重新支付', history.back();
duration: 2000, },2000);
icon: 'none' } else if (res.err_msg === "get_brand_wcpay_request:fail") {
}); // Toast.fail('支付失败', 3);
// 回退上一页重新支付 uni.showToast({
setTimeout(() => { title: '支付失败,请重新支付',
history.back(); duration: 2000,
},2000); icon: 'none'
// 提示支付失败,关闭当前页面 });
// setTimeout(function() { // 回退上一页重新支付
//这个可以关闭安卓系统的手机 setTimeout(() => {
// document.addEventListener( history.back();
// "WeixinJSBridgeReady", },2000);
// function() { // 提示支付失败,关闭当前页面
// WeixinJSBridge.call("closeWindow"); // setTimeout(function() {
// }, //这个可以关闭安卓系统的手机
// false // document.addEventListener(
// ); // "WeixinJSBridgeReady",
// //这个可以关闭ios系统的手机 // function() {
// WeixinJSBridge.call("closeWindow"); // WeixinJSBridge.call("closeWindow");
// this.$jump(`${url}?app=member`); // },
// }, 300); // false
} else { // );
uni.showToast({ // //这个可以关闭ios系统的手机
title: '未知错误,刷新重试', // WeixinJSBridge.call("closeWindow");
duration: 2000, // this.$jump(`${url}?app=member`);
icon: 'none' // }, 300);
}); } else {
} uni.showToast({
title: '未知错误,刷新重试',
duration: 2000,
icon: 'none'
});
}
}
);
} }
); })
}, },
goBack(){ goBack(){
this.$backup(); this.$backup();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment