Commit 265edc7b authored by 潘永坪's avatar 潘永坪

支付宝小程序开发

parent 2766f0ba
...@@ -7,8 +7,9 @@ ...@@ -7,8 +7,9 @@
export default { export default {
onLaunch: function(options) {//初始化完成时触发(全局只触发一次 onLaunch: function(options) {//初始化完成时触发(全局只触发一次
let path=options.path let path=options.path
let openid=uni.getStorageSync("openid") uni.setStorageSync("enterUrl",path)
if(!openid&&path.indexOf("pages/ourPayment/ourPayment")==-1){//扫码支付页面不需要在此登录 let token=uni.getStorageSync("token")
if(!token&&path.indexOf("pages/ourPayment/ourPayment")==-1){//扫码支付页面不需要在此登录
setTimeout(()=>{//解决关联普通二维码扫码首次进入时一直显示登录中 setTimeout(()=>{//解决关联普通二维码扫码首次进入时一直显示登录中
uni.navigateTo({ uni.navigateTo({
url: "/pages/login/login" url: "/pages/login/login"
......
...@@ -10,7 +10,7 @@ const request = (url = '', data = {}, type = 'POST') => { ...@@ -10,7 +10,7 @@ const request = (url = '', data = {}, type = 'POST') => {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
uni.request({ uni.request({
method: type, method: type,
url: baseUrl + url+'?token='+uni.getStorageSync("openid"), url: baseUrl + url+'?token='+uni.getStorageSync("token"),
data:data, data:data,
dataType: 'json', dataType: 'json',
}).then((response) => { }).then((response) => {
......
<template> <template>
<view> <view>
<!--#ifdef MP-WEIXIN -->
<web-view :src="outUrl"></web-view> <web-view :src="outUrl"></web-view>
<!--#endif-->
</view> </view>
</template> </template>
......
<template> <template>
<view> <view>
<!--#ifdef MP-WEIXIN -->
<web-view :src="outUrl"></web-view> <web-view :src="outUrl"></web-view>
<!--#endif-->
</view> </view>
</template> </template>
......
<template> <template>
<view > <view >
<!--#ifdef MP-ALIPAY -->
<!-- <view class="top"> <!-- <view class="top">
<view class="top-search"> <view class="top-search">
</view> </view>
...@@ -66,8 +66,7 @@ ...@@ -66,8 +66,7 @@
</view> </view>
</view> --> </view> -->
<!--#endif--> <!-- <text @click="getUserInfo()"> 授权获取头像昵称 </text> -->
<!-- <button @click="getUserInfo()"> 授权获取头像昵称 </button> -->
<view class="bottom"> <view class="bottom">
<web-view :src="outUrl"></web-view> <web-view :src="outUrl"></web-view>
</view> </view>
...@@ -81,9 +80,12 @@ ...@@ -81,9 +80,12 @@
outUrl:"",//跳出地址 outUrl:"",//跳出地址
} }
}, },
onLoad() { onLoad(){
let pdOpenid=uni.getStorageSync("openid")//胖丁小程序openid,临时用,当公众号授权做好之后可以删除 let pdOpenid=uni.getStorageSync("openid")//胖丁小程序openid,临时用,当公众号授权做好之后可以删除
this.outUrl="https://wx.pangdly.com/#/home?pdOpenid="+pdOpenid let pdToken=uni.getStorageSync("token")
let pdCreateUserId=uni.getStorageSync("createUserId")
let pdUserId=uni.getStorageSync("userId")
this.outUrl="https://wx.pangdly.com/#/home?pdOpenid="+pdOpenid+"&pdToken="+pdToken+"&pdCreateUserId="+pdCreateUserId+"&pdUserId="+pdUserId
}, },
methods: { methods: {
getUserInfo() { // 获取用户信息 getUserInfo() { // 获取用户信息
......
...@@ -37,18 +37,50 @@ ...@@ -37,18 +37,50 @@
if(res.code=='00'){ if(res.code=='00'){
let openid=res.data.openid let openid=res.data.openid
uni.setStorageSync('openid',openid) uni.setStorageSync('openid',openid)
uni.navigateBack({ let userId=res.data.userId||""
delta:1 let datas={openid,source,userId}
_this.$request("wechatUser/login/findWxUserAndLogin",datas).then((res)=>{//通过openid获取token
if(res.code=="00"){
let token=res.data.token||""
uni.setStorageSync('token',token)
let createUserId=res.data.personId||""
uni.setStorageSync('createUserId',createUserId)
let userId=res.data.userId||""
uni.setStorageSync('userId',userId)
let enterUrl=uni.getStorageSync("enterUrl")
if(token){
uni.redirectTo({
url:"/"+enterUrl
})
// uni.navigateBack({
// delta:1
// })
}
}else{
uni.showToast({
title:res.message,
icon:"none"
})
}
}).catch((err)=>{
uni.showToast({
title:"登录失败",
icon:"none"
})
}) })
}else{ }else{
uni.removeStorageSync('openid') // uni.removeStorageSync('openid')
uni.showToast({ uni.showToast({
title:res.message, title:res.message,
icon:"none" icon:"none"
}) })
} }
}).catch((err)=>{ }).catch((err)=>{
uni.removeStorageSync('openid') // uni.removeStorageSync('openid')
uni.showToast({
title:"登录失败",
icon:"none"
})
}) })
} }
} }
......
<template> <template>
<view> <view>
<!--#ifdef MP-WEIXIN -->
<web-view :src="outUrl"></web-view> <web-view :src="outUrl"></web-view>
<!--#endif-->
</view> </view>
</template> </template>
......
...@@ -180,9 +180,7 @@ ...@@ -180,9 +180,7 @@
} else { //小商家没有merchantId } else { //小商家没有merchantId
this.initTwo() this.initTwo()
} }
//#ifdef MP-WEIXIN
this.initCoupon() this.initCoupon()
//#endif
}else{ }else{
this.login() this.login()
} }
...@@ -217,10 +215,7 @@ ...@@ -217,10 +215,7 @@
} else { //小商家没有merchantId } else { //小商家没有merchantId
_this.initTwo() _this.initTwo()
} }
//#ifdef MP-WEIXIN
_this.initCoupon() _this.initCoupon()
//#endif
}else{ }else{
uni.removeStorageSync('openid') uni.removeStorageSync('openid')
} }
...@@ -244,9 +239,7 @@ ...@@ -244,9 +239,7 @@
},200) },200)
clearTimeout(this.flag) clearTimeout(this.flag)
this.flag = setTimeout(()=>{ this.flag = setTimeout(()=>{
//#ifdef MP-WEIXIN
this.initCoupon() this.initCoupon()
//#endif
}, 1500) }, 1500)
}, },
clickEnter(){//---------------------------------------------------------------------退格 clickEnter(){//---------------------------------------------------------------------退格
...@@ -257,9 +250,7 @@ ...@@ -257,9 +250,7 @@
},200) },200)
clearTimeout(this.flag) clearTimeout(this.flag)
this.flag = setTimeout(()=>{ this.flag = setTimeout(()=>{
//#ifdef MP-WEIXIN
this.initCoupon() this.initCoupon()
//#endif
}, 1500) }, 1500)
}, },
couponChoose(data) { //---------------------------------------------------------------子组件券选择之后触发的事件 couponChoose(data) { //---------------------------------------------------------------子组件券选择之后触发的事件
...@@ -441,9 +432,9 @@ ...@@ -441,9 +432,9 @@
provider: 'alipay', // 服务提供商 支付宝支付: alipay 微信支付: wxpay provider: 'alipay', // 服务提供商 支付宝支付: alipay 微信支付: wxpay
orderInfo: this.orderInfo, // 支付宝订单号 orderInfo: this.orderInfo, // 支付宝订单号
success: function (res) { success: function (res) {
// uni.redirectTo({ uni.redirectTo({
// url:"../paySuccess/paySuccess" url:"../paySuccess/paySuccess?orderId="+_this.orderId
// }) })
}, },
fail: function (err) { fail: function (err) {
uni.showToast({ uni.showToast({
......
项目介绍文件 项目介绍文件
一、本地存储数据 一、本地存储数据
1.uni.getStorageSync("openid") 1.uni.getStorageSync("openid") //openid
2.uni.getStorageSync("alipayQrCode") 2.uni.getStorageSync("token") //token
3.uni.getStorageSync("createUserId") //当前用户的id
4.uni.getStorageSync("userId") //平台id
5.uni.getStorageSync("alipayQrCode") //支付宝参数码
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