提交 dec9fb8d 编写于 作者: VK1688's avatar VK1688

uni-pay示例支持微信小程序支付

上级 9b5f6386
......@@ -7,17 +7,18 @@
<view>
<view class="label">支付金额(单位分,100=1元):</view>
<view><input class="input" v-model.number="total_fee" /></view>
</view>
<button class="button" @click="open()">打开收银台(弹窗模式)</button>
</view>
<!-- #ifdef APP || H5 -->
<button class="button" @click="open()">打开收银台(弹窗模式)</button>
<view v-if="!isPcCom">
<button class="button" @click="toPayDesk">打开收银台(新页面模式)</button>
</view>
<!-- #endif -->
<!-- #endif -->
<!-- #ifdef MP-WEIXIN || H5 || APP -->
<button class="button" @click="createOrder('wxpay')">发起支付(微信)</button>
<!-- #endif -->
<!-- #endif -->
<!-- #ifdef MP-ALIPAY || H5 || APP -->
<button class="button" @click="createOrder('alipay')">发起支付(支付宝)</button>
<!-- #endif -->
......
## 1.1.0(2024-11-29)
支持微信小程序支付 HBX最低版本 4.41 [详情](https://doc.dcloud.net.cn/uniCloud/uni-pay/uni-app-x.html#config-wxpay-mp)
## 1.0.5(2024-09-29)
修复 微信支付v3 h5支付兼容性问题
## 1.0.4(2024-08-24)
支持苹果虚拟支付 HBX最低版本 4.26 [详情](https://doc.dcloud.net.cn/uniCloud/uni-pay/uni-app-x.html#appleiap)
## 1.0.2(2024-04-28)
支持微信支付
## 1.0.1(2024-04-28)
兼容uni-app-x对客户端uniPlatform的调整(uni-app-x内uniPlatform区分app-android、app-ios)
## 1.0.0(2024-03-11)
uni-pay-x 发布
......@@ -122,7 +122,7 @@
<script>
// 引入支付云对象
const uniPayCo = uniCloud.importObject("uni-pay-co");
import { checkPlatform, objectAssign } from "../../js_sdk/js_sdk"
import { checkPlatform, objectAssign, getWeixinCode, getAlipayCode } from "../../js_sdk/js_sdk"
export default {
name: "uni-pay",
emits: ["success", "cancel", "fail", "create", "mounted", "qrcode"],
......@@ -210,6 +210,30 @@
}
},
mounted() {
// #ifdef MP-WEIXIN || MP-ALIPAY
if (this.openid == "") {
new Promise(async (resolve, reject) => {
let code = await this.getCode();
let res = await this.getOpenid({
// #ifdef MP-WEIXIN
provider: "wxpay",
// #endif
// #ifdef MP-ALIPAY
provider: "alipay",
// #endif
code
});
resolve(res);
}).then((res) => {
if (res['openid'] != null) {
this.openid = res['openid'];
}
}).catch((err) => {
reject(err);
})
}
// #endif
// #ifdef MP-WEIXIN
// 如果是微信小程序,则设置只支持微信支付
this.originalRroviders = ["wxpay"];
......@@ -312,6 +336,11 @@
createOrderData['openid'] = options['openid'];
}
// #endif
// #ifdef MP
if (this.openid != "") {
createOrderData['openid'] = this.openid;
}
// #endif
try {
let res = await uniPayCo.createOrder(createOrderData);
if (res['errCode'] == 0) {
......@@ -379,6 +408,9 @@
uni.requestPayment({
provider: res['provider'] as string,
orderInfo: orderStr,
// #ifdef MP-WEIXIN
..._order,
// #endif
success: (res) => {
console.log("requestPaymentSuccess", JSON.stringify(res))
this._getOrder();
......@@ -780,7 +812,18 @@
uni.hideLoading()
}
// #endif
}
},
// #ifdef MP-WEIXIN || MP-ALIPAY
// 获取code
async getCode() : Promise<string>{
// #ifdef MP-WEIXIN
return getWeixinCode();
// #endif
// #ifdef MP-ALIPAY
return getAlipayCode();
// #endif
},
// #endif
},
watch: {
......
......@@ -67,8 +67,49 @@ function objectAssign(json1:UTSJSONObject,json2:UTSJSONObject) :UTSJSONObject{
return json1;
}
function getWeixinCode () : Promise<string>{
return new Promise((resolve, reject) => {
// #ifdef MP-WEIXIN
uni.login({
provider: 'weixin',
success(res) {
resolve(res.code)
},
fail(err) {
reject(new Error('获取微信code失败'))
}
})
// #endif
// #ifndef MP-WEIXIN
resolve('')
// #endif
})
};
function getAlipayCode () : Promise<string>{
return new Promise((resolve, reject) => {
// #ifdef MP-ALIPAY
uni.login({
provider: 'alipay',
success(res) {
resolve(res.code);
},
fail(err) {
reject(new Error('获取支付宝code失败,可能是没有关联appid或你的支付宝开发者工具还没有登录'));
}
});
// #endif
// #ifndef MP-ALIPAY
resolve('');
// #endif
});
};
export {
checkPlatform,
getH5Env,
objectAssign,
getWeixinCode,
getAlipayCode
};
\ No newline at end of file
{
"id": "uni-pay-x",
"displayName": "uni-pay-x",
"version": "1.0.0",
"description": "uni-pay-x",
"keywords": [
"uni-pay-x"
],
"version": "1.1.0",
"description": "uni-pay 的 uni-app x版本,需HBX≥4.02",
"keywords": [
"uni-pay-x",
"微信支付",
"支付宝",
"苹果虚拟支付"
],
"repository": "",
"engines": {
"HBuilderX": "^3.1.0"
"HBuilderX": "^4.02"
},
"dcloudext": {
"type": "unicloud-template-page",
......@@ -24,9 +27,9 @@
"qq": ""
},
"declaration": {
"ads": "",
"data": "",
"permissions": ""
"ads": "",
"data": "插件不采集任何数据",
"permissions": ""
},
"npmurl": ""
},
......@@ -41,41 +44,42 @@
},
"client": {
"Vue": {
"vue2": "u",
"vue2": "n",
"vue3": "y"
},
"App": {
"app-vue": "n",
"app-nvue": "n",
"app-uvue": "y"
"app-vue": "n",
"app-nvue": "n",
"app-uvue": "y",
"app-harmony": "u"
},
"H5-mobile": {
"Safari": "u",
"Android Browser": "u",
"微信浏览器(Android)": "u",
"QQ浏览器(Android)": "u"
"Safari": "y",
"Android Browser": "y",
"微信浏览器(Android)": "y",
"QQ浏览器(Android)": "y"
},
"H5-pc": {
"Chrome": "u",
"IE": "u",
"Edge": "u",
"Firefox": "u",
"Safari": "u"
"Chrome": "y",
"IE": "n",
"Edge": "y",
"Firefox": "y",
"Safari": "y"
},
"小程序": {
"微信": "u",
"阿里": "u",
"百度": "u",
"字节跳动": "u",
"QQ": "u",
"钉钉": "u",
"快手": "u",
"飞书": "u",
"京东": "u"
"微信": "n",
"阿里": "n",
"百度": "n",
"字节跳动": "n",
"QQ": "n",
"钉钉": "n",
"快手": "n",
"飞书": "n",
"京东": "n"
},
"快应用": {
"华为": "u",
"联盟": "u"
"华为": "n",
"联盟": "n"
}
}
}
......
# uni-pay-x
\ No newline at end of file
`uni-pay-x``uni-pay``uni-app x`[文档地址](https://doc.dcloud.net.cn/uniCloud/uni-pay/uni-app-x.html)
**线上体验地址**
![](https://web-ext-storage.dcloud.net.cn/unicloud/uni-pay-x/518.png)
......@@ -94,5 +94,17 @@
],
"MgoIsUnique": false
}
},
{
"IndexName": "appleiap_account_token",
"MgoKeySchema": {
"MgoIndexKeys": [
{
"Name": "appleiap_account_token",
"Direction": "1"
}
],
"MgoIsUnique": false
}
}
]
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册