微信支付(uniapp公众号)

首先做微信支付的话是需要code

加载的时候放下边代码

if (option.code != null && (this.openid == null || this.openid == '')) {
                this.code = option.code
                this.getOpenId()
            }
            if (url.indexOf('?code=') != -1 && (this.openid == null || this.openid == '')) {
                this.code = url.substring(url.indexOf('?code=') + 6, url.indexOf('&state='));
                this.getOpenId()
                console.log(this.code)
            } else {
                console.log("不需要code切割")
            }

这是触发方法,唤醒支付

// 这是H5微信支付
            h5pay() {
                
                let that = this
                if (that.openid && that.openid !== '' && that.openid !== 'undefined') {
                    if (this.priceIndex == 0) {
                        this.getordinary()
                    } else if (this.priceIndex == 1 || this.priceIndex == 3) {
                        // 团购支付
                        this.getBuybuing()
                    }

                } else {
                    if (that.code) {
                        console.log("33")
                        uni.request({
                            url: helper.api + '/app/wxPay/getTokenByCode',
                            method: 'GET',
                            header: {
                                'content-type': 'app

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
uniapp微信公众支付需要通过网页授权获取微信的code来实现。首先,需要在配置中设置回调域名。然后,通过后端接口获取支付配置信息。对于微信支付,可以使用以下代码获取配置信息: ``` await this.$http({ apiName: "wxPayConfig", type: "POST", data: { orderId: this.orderId } }).then(res => { // 处理返回的支付配置信息 }).catch(_ => { // 处理异常情况 }); ``` 对于支付支付,需要单独从接口获取配置信息,得到的是一长串字符串: ``` await this.$http({ apiName: "aliPay", type: "POST", data: { orderNo: this.orderId } }).then(res => { // 处理返回的支付配置信息 }).catch(_ => { // 处理异常情况 }); ``` 通过以上步骤,可以在uniapp中实现微信公众支付。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [uniapp微信H5公众号授权与支付](https://blog.csdn.net/qq_63358859/article/details/127021504)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [uniapp之APP/微信小程序/公众支付](https://blog.csdn.net/weixin_36185028/article/details/106328412)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

沐卿゚

帅哥美女多多支持哦,希望能帮助

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值