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

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

上级 9b5f6386
...@@ -7,17 +7,18 @@ ...@@ -7,17 +7,18 @@
<view> <view>
<view class="label">支付金额(单位分,100=1元):</view> <view class="label">支付金额(单位分,100=1元):</view>
<view><input class="input" v-model.number="total_fee" /></view> <view><input class="input" v-model.number="total_fee" /></view>
</view> </view>
<button class="button" @click="open()">打开收银台(弹窗模式)</button>
<!-- #ifdef APP || H5 --> <!-- #ifdef APP || H5 -->
<button class="button" @click="open()">打开收银台(弹窗模式)</button>
<view v-if="!isPcCom"> <view v-if="!isPcCom">
<button class="button" @click="toPayDesk">打开收银台(新页面模式)</button> <button class="button" @click="toPayDesk">打开收银台(新页面模式)</button>
</view> </view>
<!-- #endif -->
<!-- #endif -->
<!-- #ifdef MP-WEIXIN || H5 || APP --> <!-- #ifdef MP-WEIXIN || H5 || APP -->
<button class="button" @click="createOrder('wxpay')">发起支付(微信)</button> <button class="button" @click="createOrder('wxpay')">发起支付(微信)</button>
<!-- #endif --> <!-- #endif -->
<!-- #ifdef MP-ALIPAY || H5 || APP --> <!-- #ifdef MP-ALIPAY || H5 || APP -->
<button class="button" @click="createOrder('alipay')">发起支付(支付宝)</button> <button class="button" @click="createOrder('alipay')">发起支付(支付宝)</button>
<!-- #endif --> <!-- #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 @@ ...@@ -122,7 +122,7 @@
<script> <script>
// 引入支付云对象 // 引入支付云对象
const uniPayCo = uniCloud.importObject("uni-pay-co"); 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 { export default {
name: "uni-pay", name: "uni-pay",
emits: ["success", "cancel", "fail", "create", "mounted", "qrcode"], emits: ["success", "cancel", "fail", "create", "mounted", "qrcode"],
...@@ -210,6 +210,30 @@ ...@@ -210,6 +210,30 @@
} }
}, },
mounted() { 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 // #ifdef MP-WEIXIN
// 如果是微信小程序,则设置只支持微信支付 // 如果是微信小程序,则设置只支持微信支付
this.originalRroviders = ["wxpay"]; this.originalRroviders = ["wxpay"];
...@@ -312,6 +336,11 @@ ...@@ -312,6 +336,11 @@
createOrderData['openid'] = options['openid']; createOrderData['openid'] = options['openid'];
} }
// #endif // #endif
// #ifdef MP
if (this.openid != "") {
createOrderData['openid'] = this.openid;
}
// #endif
try { try {
let res = await uniPayCo.createOrder(createOrderData); let res = await uniPayCo.createOrder(createOrderData);
if (res['errCode'] == 0) { if (res['errCode'] == 0) {
...@@ -379,6 +408,9 @@ ...@@ -379,6 +408,9 @@
uni.requestPayment({ uni.requestPayment({
provider: res['provider'] as string, provider: res['provider'] as string,
orderInfo: orderStr, orderInfo: orderStr,
// #ifdef MP-WEIXIN
..._order,
// #endif
success: (res) => { success: (res) => {
console.log("requestPaymentSuccess", JSON.stringify(res)) console.log("requestPaymentSuccess", JSON.stringify(res))
this._getOrder(); this._getOrder();
...@@ -780,7 +812,18 @@ ...@@ -780,7 +812,18 @@
uni.hideLoading() uni.hideLoading()
} }
// #endif // #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: { watch: {
......
...@@ -67,8 +67,49 @@ function objectAssign(json1:UTSJSONObject,json2:UTSJSONObject) :UTSJSONObject{ ...@@ -67,8 +67,49 @@ function objectAssign(json1:UTSJSONObject,json2:UTSJSONObject) :UTSJSONObject{
return json1; 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 { export {
checkPlatform, checkPlatform,
getH5Env, getH5Env,
objectAssign, objectAssign,
getWeixinCode,
getAlipayCode
}; };
\ No newline at end of file
{ {
"id": "uni-pay-x", "id": "uni-pay-x",
"displayName": "uni-pay-x", "displayName": "uni-pay-x",
"version": "1.0.0", "version": "1.1.0",
"description": "uni-pay-x", "description": "uni-pay 的 uni-app x版本,需HBX≥4.02",
"keywords": [ "keywords": [
"uni-pay-x" "uni-pay-x",
], "微信支付",
"支付宝",
"苹果虚拟支付"
],
"repository": "", "repository": "",
"engines": { "engines": {
"HBuilderX": "^3.1.0" "HBuilderX": "^4.02"
}, },
"dcloudext": { "dcloudext": {
"type": "unicloud-template-page", "type": "unicloud-template-page",
...@@ -24,9 +27,9 @@ ...@@ -24,9 +27,9 @@
"qq": "" "qq": ""
}, },
"declaration": { "declaration": {
"ads": "", "ads": "",
"data": "", "data": "插件不采集任何数据",
"permissions": "" "permissions": ""
}, },
"npmurl": "" "npmurl": ""
}, },
...@@ -41,41 +44,42 @@ ...@@ -41,41 +44,42 @@
}, },
"client": { "client": {
"Vue": { "Vue": {
"vue2": "u", "vue2": "n",
"vue3": "y" "vue3": "y"
}, },
"App": { "App": {
"app-vue": "n", "app-vue": "n",
"app-nvue": "n", "app-nvue": "n",
"app-uvue": "y" "app-uvue": "y",
"app-harmony": "u"
}, },
"H5-mobile": { "H5-mobile": {
"Safari": "u", "Safari": "y",
"Android Browser": "u", "Android Browser": "y",
"微信浏览器(Android)": "u", "微信浏览器(Android)": "y",
"QQ浏览器(Android)": "u" "QQ浏览器(Android)": "y"
}, },
"H5-pc": { "H5-pc": {
"Chrome": "u", "Chrome": "y",
"IE": "u", "IE": "n",
"Edge": "u", "Edge": "y",
"Firefox": "u", "Firefox": "y",
"Safari": "u" "Safari": "y"
}, },
"小程序": { "小程序": {
"微信": "u", "微信": "n",
"阿里": "u", "阿里": "n",
"百度": "u", "百度": "n",
"字节跳动": "u", "字节跳动": "n",
"QQ": "u", "QQ": "n",
"钉钉": "u", "钉钉": "n",
"快手": "u", "快手": "n",
"飞书": "u", "飞书": "n",
"京东": "u" "京东": "n"
}, },
"快应用": { "快应用": {
"华为": "u", "华为": "n",
"联盟": "u" "联盟": "n"
} }
} }
} }
......
# uni-pay-x `uni-pay-x``uni-pay``uni-app x`[文档地址](https://doc.dcloud.net.cn/uniCloud/uni-pay/uni-app-x.html)
\ No newline at end of file
**线上体验地址**
![](https://web-ext-storage.dcloud.net.cn/unicloud/uni-pay-x/518.png)
...@@ -94,5 +94,17 @@ ...@@ -94,5 +94,17 @@
], ],
"MgoIsUnique": false "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.
先完成此消息的编辑!
想要评论请 注册