uniapp APP微信登录、支付、分享以及支付宝支付 实战踩坑记录
1、微信支付和支付宝支付
先上代码、封装好了的组件
html部分
<template>
<view class="rows">
<!------------------------------充值的弹框开始------------------------------>
<uni-popup class="common-popup" ref="popupChongZhi" :is-mask-click="false" type="bottom">
<uni-icons class="close" type="closeempty" @click="$refs.popupChongZhi.close()"></uni-icons>
<text class="popup-title">充值</text>
<view class="czlist">
<view v-for="(item,index) in balan" :class="{ 'activeCss': active == index }"
@click="activeHandler(index)">
<text class="em-price">{{ item.tmdNumber }}</text>
<text>¥{{systemStyle?item.goodsPriceAndroid:item.goodsPriceIos }}</text>
</view>
</view>
<view class="yue">余额:<text class="em-price">{{ userInfo.accountBalance + userInfo.giftBalance }}</text>
</view>
<view class="xieyi">充值即同意<navigator url="/pages/other/agreement?agremType=3">《充值协议》</navigator>
</view>
<button @click="iosAndAndroid" :disabled="btnloading">充值</button>
</uni-popup>
<!------------------------------充值的弹框结束------------------------------>
<!-- 选择充值方式 -->
<uni-popup class="common-popup" ref="modeOfPayment" :is-mask-click="false" type="bottom">
<uni-icons class="close" type="closeempty" @click="$refs.modeOfPayment.close()"></uni-icons>
<text class="popup-title">选择充值方式</text>
<view class="wxZfb">
<radio-group @change="radioChange">
<label class="uni-list-cell uni-list-cell-pd">
<view class="radioBox">
<image src="@/static/img/common/wx.png" mode="aspectFill" />
<view>微信支付</view>
<radio value="WXPAY" :checked="true" color="#B48732" />
</view>
</label>
<label class="uni-list-cell uni-list-cell-pd zfb">
<view class="radioBox">
<image src="@/static/img/common/zfb.png" mode="aspectFill" />
<view>支付宝支付</view>
<radio value="ALIPAY" color="#B48732" />
</view>
</label>
</radio-group>
<button @click="ontopThat">立即支付</button>
</view>
</uni-popup>
<!-- 主动查询订单状态 -->
<uni-popup class="common-popup" ref="inquire" :is-mask-click="false" type="center">
<text class="popup-title">是否支付完成</text>
<button :disabled="btnloading" @click='inquireHandler'>已支付</button>
<button :disabled="btnloading" class="wzf" @click="$refs.inquire.close()">未支付</button>
</uni-popup>
</view>
</template>
css部分:
<style scoped>
.wxZfb image {
width: 56rpx;
height: 56rpx;
}
.wxZfb .radioBox {
display: flex;
font-size: 28rpx;
font-family: PingFangSC-Regular, PingFang SC;
font-weight: 400;
color: rgba(0, 0, 0, 0.8);
align-items: center;
padding: 32rpx 0;
border-bottom: 1rpx solid #EEEEEE;
}
.wxZfb .radioBox view {
margin-left: 24rpx;
}
.wxZfb .radioBox radio {
flex: 1;
text-align: right;
}
.wxZfb .radioBox:nth-last-child(1) {
padding-bottom: 78rpx;
}
.common-popup .wzf {
background: transparent;
color: #000;
border: 1px solid #ccc;
}
</style>
/*-------下面这段有多余其它代码需要筛除--------*/
/*------------------------------充值的弹框开始------------------------------*/
.common-popup {
background: #fff!important;
}
.czlist .activeCss {
border-color: #B48732
}
/deep/.uni-popup__wrapper.bottom{
background-color: #fff!important;
}
.common-popup/deep/ .uni-popup__wrapper{
width: auto;
padding: 32rpx 40rpx 40rpx;
}
.popup-title{
margin-bottom: 0;
line-height: 56rpx;
font-size: 40rpx;
font-weight: 500;
}
.czlist{
display: flex;
flex-wrap: wrap;
margin-top: 32rpx;
}
.czlist>view{
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 210rpx;
height: 150rpx;
border: 2rpx solid rgba(180, 135, 50, .06);
margin-left: 20rpx;
border-radius: 16rpx;
background-color: rgba(180, 135, 50, .06);
}
.czlist>view:nth-child(3n-2){margin-left: 0}
.czlist>view:nth-child(3n)~view{margin-top: 20rpx}
.czlist>view.active{border-color: #B48732}
.czlist>view .em-price{
display: flex;
font-size: 36rpx;
}
.czlist>view .em-price:before{
width: 32rpx;
height: 32rpx;
margin-right: 8rpx;
line-height: 32rpx;
}
.czlist>view text:nth-child(2){
margin-top: 22rpx;
line-height: 24rpx;
font-size: 24rpx;
color: rgba(0,0,0,0.2);
}
.yue{
display: flex;
align-items: center;
margin-top: 56rpx;
line-height: 40rpx;
font-size: 28rpx;
}
.yue .em-price{
display: flex;
font-size: 32rpx;
}
.yue .em-price:before{
width: 28rpx;
height: 28rpx;
}
.xieyi{
display: flex;
margin-top: 32rpx;
font-size: 24rpx;
color: rgba(0,0,0,0.2);
align-items: center;
justify-content: center;
}
.xieyi navigator{color: #5A4614;}
.uni-popup__wrapper uni-button{
width: 650rpx;
height: 88rpx;
margin-top: 20rpx;
line-height: 88rpx;
font-size: 32rpx;
font-weight: 500;
border-radius: 88rpx;
}
.quanmatip{
margin-top: 80rpx;
font-size: 32rpx;
font-weight: 500;
line-height: 44rpx;
}
.common-popup input{
height: 84rpx;
padding: 0 32rpx;
margin: 32rpx 0 80rpx;
background-color: #F9F9F9;
border-radius: 42rpx;
overflow: hidden;
align-items: center;
justify-content: space-between;
}
js逻辑代码
<script>
import {
mapState
} from "vuex";
export default {
computed: {
...mapState(['hasLogin', 'userInfo'])
},
data() {
return {
btnloading: false,
active: 0,
balan: [], //充值数据配置
agreementData: [], //用户协议数据
radioVal: "WXPAY", //默认选中1微信2支付宝
show: false, //弹出层显隐
queryData: {
paymentPlatform: 'APP',
paymentChannel: 'WXPAY',
},
orderForm: undefined, //订单ID
systemStyle: 1 //0ios,1安卓
}
},
onLoad(option) {
this.balanCeconfiguration()
this.agreementHandler()
},
methods: {
// 判断是ios还是安卓
iosAndAndroid() {
if (this.systemStyle) {
this.$refs.modeOfPayment.open();
return
}
uni.showToast({
title: "IOS支付暂未开放,请耐心等待!",
icon: 'none',
mask: true,
duration: 2500,
});
// IOS支付
},
open() {
this.$refs.popupChongZhi.open();
},
/*------------------------充值开始-----------------------*/
activeHandler(index) {
this.active = index;
this.queryData.configId = this.balan[index].configId;
},
// 充值配置
balanCeconfiguration() {
let ua = uni.getSystemInfoSync().platform;
if (/ios/i.test(ua)) {
this.systemStyle = 0
} else {
this.systemStyle = 1
}
this.$request.get('/app/order/tmdConfig').then(res => {
this.balan = res.data;
this.queryData.configId = res.data[0].configId
})
},
// 充值协议
agreementHandler() {
// 1用户协议 2隐私协议 3购买须知
this.$request.get(`/app/user/getAgreement/3`).then(res => {
this.agreementData = res.data;
})
},
// 点击充值
ontopThat() {
this.queryData.paymentChannel = this.radioVal;
this.$request.post(`/pay/placeOrder`, this.queryData).then(response => {
this.orderForm = response.data.orderId;
uni.hideLoading();
if (this.radioVal == 'ALIPAY') {
uni.requestPayment({
provider: 'alipay',
orderInfo: response.data.url, //微信、支付宝订单数据 【注意微信的订单信息,键值应该全部是小写,不能采用驼峰命名】
success: (res) => {
this.$refs.modeOfPayment.close();
this.$refs.inquire.open();
},
fail: (err) => {}
});
return
}
// 微信支付
let orderInfo = {
appid: response.data.appId, // 微信开放平台 - 应用 - AppId,注意和微信小程序、公众号 AppId 可能不一致
noncestr: response.data.nonceStr, // 随机字符串
package: response.data.package, // 固定值
partnerid: response.data.partnerid, // 微信支付商户号
prepayid: response.data.url, // 统一下单订单号
timestamp: response.data.timeStamp, // 时间戳(单位:秒)
sign: response.data.paySign // 签名,这里用的 MD5/RSA 签名
}
console.log(11111,orderInfo.appid);
uni.requestPayment({
provider: "wxpay",
orderInfo: orderInfo,
success: (res) => {
this.$refs.modeOfPayment.close();
this.$refs.inquire.open();
},
fail(e) {
if (e && e.code == -8) {
uni.showToast({
title: "支付失败,未安装微信客户端",
icon: 'none',
mask: true,
duration: 2500,
});
return
}
uni.showToast({
title: `支付失败`,
icon: 'none',
mask: true,
duration: 2500,
});
}
})
})
},
radioChange(val) {
this.radioVal = val.target.value; //默认选中1微信2支付宝
},
inquireHandler() {
console.log("参数1", this.orderForm)
console.log("参数2", this.queryData.paymentChannel)
this.$request.get(`/pay/queryPay/${this.orderForm}/${this.queryData.paymentChannel}`).then(res => {
this.$refs.inquire.close()
this.$emit('getTableTmd')
if (res.data) {
uni.showToast({
title: "支付成功",
icon: 'none',
mask: true,
duration: 2500,
});
} else {
uni.showToast({
title: "支付失败",
icon: 'none',
mask: true,
duration: 2500,
});
}
})
}
}
}
</script>
需要应用界面调用组件
<Recharge ref='play' v-on:getTableTmd='inquire' />
import Recharge from '@/components/recharge/recharge.vue'; //支付弹窗
// 刷新数据 支付成功后刷新充值数据
inquire() {
this.getTableTmd();
this.$store.dispatch('GetInfo').then((res) => {}).catch(err => {})
},
2、微信登录
3、微信分享
uniapp APP微信登录、支付、分享以及支付宝支付 实战踩坑记录的更多相关文章
- 关于微信小程序获取二维码的踩坑记录
1.踩坑需求:获取小程序的二维码 2.踩坑接口: https://api.weixin.qq.com/wxa/getwxacode?access_token=ACCESS_TOKEN3 踩坑代码 pu ...
- iOS开发笔记14:微博/微信登录与分享、微信/支付宝支付
产品中接入了微博/微信的第三方登录分享功能.微信和支付宝的第三方支付功能,之前在开发过程中涉及到这些部分,于是抽空将接入过程梳理了一遍. 1.微博.微信.支付宝SDK相关接入设置 (1)微博SDK S ...
- 详解Android微信登录与分享
Android 使用微信登录.分享功能 具体的文档详情微信官网上介绍(微信官网文档),本人直接按照项目部署步骤进行讲解: 第一步:申请你的AppID: 第二步:依赖 dependencies { co ...
- 李洪强iOS开发支付集成之支付宝支付
iOS开发支付集成之支付宝支付 下载支付宝SDK 首先是开发包下载,还是比较难发现的,网上以前文章中的链接都打不开,我找了好久才找到的.最新的地址在这里(注意的是下载出来的SDK包里面并没有传说中的开 ...
- VUE使用微信JDK(附踩坑记录)
VUE使用微信分享SDK(附踩坑记录) 微信分享官方文档 安装JS-SDK npm i -S weixin-jsapi 引入包 ES5 写法 const wx = require('weixin-js ...
- Android微信登录、分享、支付
转载需要著名出处: http://blog.csdn.net/lowprofile_coding/article/details/78004224 之前写过微信登录分享支付第一版: http://bl ...
- 手把手教你完成App支付JAVA后台-支付宝支付JAVA
接着上一篇博客,我们暂时完成了手机端的部分支付代码,接下来,我们继续写后台的代码. 后台基本需要到以下几个参数,我都将他们写在了properties文件中: 支付宝参数 AliPay.payURL = ...
- 微信公众号中的支付宝支付与微信支付 && 支付宝支付问题(微信bug)
一般,在微信公众号中的商城都是需要支持微信支付和支付宝支付的,当然,较大的公司对于鹅厂和阿里的站队就不说了,所以这里简单记录一下支付宝支付和微信支付的主要流程.说是简单介绍,这是因为确实不难,因为前端 ...
- mui APP 微信登录授权
一.在微信平台上申请appid.appsecret. 二.app --> manifest.json-->SDK配置(填写申请好的appid和appsecret) 三.在登录页,点击微信登 ...
- unity探索者之iOS微信登录、分享
版权声明:本文为原创文章,转载请声明http://www.cnblogs.com/unityExplorer/p/8405700.html iOS接入微信的SDK相对于安卓要麻烦一点,除了核心功能代码 ...
随机推荐
- 2022-03-31:有一组 n 个人作为实验对象,从 0 到 n - 1 编号,其中每个人都有不同数目的钱, 以及不同程度的安静值(quietness) 为了方便起见,我们将编号为 x 的人简称为
2022-03-31:有一组 n 个人作为实验对象,从 0 到 n - 1 编号,其中每个人都有不同数目的钱, 以及不同程度的安静值(quietness) 为了方便起见,我们将编号为 x 的人简称为 ...
- 2021-08-26:长度为N的数组arr,一定可以组成N^2个数字对。例如arr = [3,1,2],数字对有(3,3) (3,1) (3,2) (1,3) (1,1) (1,2) (2,3) (2
2021-08-26:长度为N的数组arr,一定可以组成N^2个数字对.例如arr = [3,1,2],数字对有(3,3) (3,1) (3,2) (1,3) (1,1) (1,2) (2,3) (2 ...
- 由C# yield return引发的思考
前言 当我们编写 C# 代码时,经常需要处理大量的数据集合.在传统的方式中,我们往往需要先将整个数据集合加载到内存中,然后再进行操作.但是如果数据集合非常大,这种方式就会导致内存占用过高,甚至可能导致 ...
- Kubernetes(k8s)健康性检查:livenessprobe探测和readinessprobe探测
目录 一.系统环境 二.前言 三.Kubernetes健康性检查简介 四.创建没有探测机制的pod 五.添加livenessprobe探测 5.1 使用command的方式进行livenessprob ...
- 蜂窝移动通信(IOT)接入流程
蜂窝物联网 蜂窝物联网(Cellular IoT)就是使用现有的蜂窝网络连接物联网设备而形成的物联网,是一种将物理设备与互联网连接起来的方式.通过蜂窝物联网,人们将一些物理设备--如传感器-- ...
- Vue3 之 响应式 API reactive、 effect源码,详细注释
Vue3之响应式 API reactive. effect源码,详细注释 目录 一.实现响应式 API:reactive.shallowReactive.readonly.shallowReadonl ...
- const 使用
宏定义与const的区别?(概念题是最容易丢分)1. 发生时机不一样: 宏定义发生在预处理时,const关键字发生编译时2. 宏定义仅仅只做了字符串的替换,没有类型检查; const关键字有类型检查, ...
- 前端 vue 自定义导航栏组件高度及返回箭头 自定义 tabbar 图标
前端vue自定义导航栏组件高度及返回箭头 自定义tabbar图标, 下载完整代码请访问uni-app插件市场地址:https://ext.dcloud.net.cn/plugin?id=12986 效 ...
- IDEA连接数据库
我只想卷死各位,或者被各位卷死 在入门案例映射配置文件中存在报红的情况.问题如下: 产生的原因:Idea和数据库没有建立连接,不识别表信息.但是大家一定要记住,它并不影响程序的执行. 解决方式:在Id ...
- 驱动开发:内核远程线程实现DLL注入
在笔者上一篇文章<内核RIP劫持实现DLL注入>介绍了通过劫持RIP指针控制程序执行流实现插入DLL的目的,本章将继续探索全新的注入方式,通过NtCreateThreadEx这个内核函数实 ...