微信小程序线上版本 wx.request发起请求调不了接口。
发布于 5 年前 作者 yongren 16088 次浏览 来自 问答

微信小程序线上版本 wx.request发起请求调不了接口。

但是使用微信开发者工具,wx.request发起请求可以调通接口。

调用接口代码示例:

//对称解密数据

                        wx.request({

                            url: ‘http://lehe.happy791.com/wxSPro/wechatDecryptData’,

                            data: {

                                encryptedData: encryptedData,

                                iv: iv,

                                code: code,

                                apiauthtoken: App.globalData.apiauthtoken

                            },

                            method: ‘POST’, // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT

                            header: { ‘content-type’: ‘application/x-www-form-urlencoded’ }, // 设置请求的 header

                            success: function (res) {

                                // success

                                //同一用户,对同一个微信开放平台下的不同应用,unionid是相同的

                                console.log(“wechatDecryptData”)

                                const openId = res.data.openId;

                                wx.setStorageSync(‘openId’, openId);

                                const unionId = res.data.unionId

 

                            },

                            fail: function () {

                                // fail

                                console.log(“对称解密数据wechatDecryptData:fail”)

                            }

                        })

3 回复

谢谢兄台的解答

在微信公众品台小程序的设置里面,进行服务器安全域名的绑定,而且只支持https,不支持http请求

线上版本要使用小程序绑定的合法域名,并且是https,你这个是http

回到顶部