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

支付宝小程序开发

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