微信小程序免ssl证书部署

2018-07-15  本文已影响0人  闪灵Anchen

配置步骤

1.登录小程序管理平台 -> 设置 -> 开发设置 -> 服务器域名 -> request合法域名,将域名修改为 https://ssl.shanling.top

2.将程序中请求域名路径重写,参考以下代码示例(以GET方法举例):

//原始代码(http链接在小程序中是无法使用的):

wx.request({

    url: 'http://您的原始路径',

    header: {

        'content-type': 'application/json'

    },

    success: function(res) {

    }

})

//改写后代码(将http转为https链接,小程序可正常访问):

wx.request({

    url: 'https://ssl.shanling.top/free/?url=' + encodeURIComponent('http://您的原始路径'),

    header: {

        'content-type': 'application/json'

    },

    success: function(res) {

    }

})

免费通道为:'https://ssl.shanling.top/free/?url=' + encodeURIComponent('http://您的原始路径')

VIP通道为:'https://ssl.shanling.top/vip/?url=' + encodeURIComponent('http://您的原始路径')

说明:免费通道可直接使用,VIP通道需要购买后使用 点击购买

用法举例

GET方法:

wx.request({

    url: 'https://ssl.shanling.top/free/?url=' + encodeURIComponent('http://您的原始路径'),

    header: {

        'content-type': 'application/json'

    },

    success: function(res) {

    }

})

POST方法:

wx.request({

    url: 'https://ssl.shanling.top/free/?url=' + encodeURIComponent('http://您的原始路径'),

    data: {

        data1: '需要post的数据1',

        data2: '需要post的数据2'

    },

    method: 'POST',

    header: {

        'content-type': 'application/x-www-form-urlencoded'

    },

    success: function (res) {

    }

})

上传文件方法:

wx.chooseImage({

    count: 1,

    sizeType: ['original', 'compressed'],

    sourceType: ['album', 'camera'],

    success: function (res) {

        var tempFilePaths = res.tempFilePaths

        wx.uploadFile({

            url: 'https://ssl.shanling.top/free/?url=' + encodeURIComponent('http://您的原始路径'),

            filePath: tempFilePaths[0],

            name: 'file',

            success: function (res) {

            }

        })

    }

})

上一篇 下一篇

猜你喜欢

热点阅读