下载支付宝开发者工具:小程序文档 - 支付宝文档中心
下载完成后填写或选择支付宝小程序开发者工具的安装路径

运行到开发者工具进行调
点击运行-->选择支付宝小程,然后等待编译,编译完成以后,你的支付宝开发工具就会自动打开,但是你的项目不会。现在需要点击右上角-->选择项目-->选择你的项目文件夹-->打开-->选择unpackage-->选择dist-->选择dev-->选择mp-alipay。这样就可以在支付宝开发工具打开项目了,不用担心,这边写了代码,支付宝开发工具上也是自动更新的。
-
支付宝小程序开放平台配置
// 支付宝小程序不支持uni.request,用my.request // #ifdef MP-ALIPAY my.request({ url: config.api() + url, method: method || "GET" , data: data, headers: header, dataType: 'json' , success: res => { // 注:因为这里对请求成功的没有统一设置抛错提示,所以后续具体组件中使用接口请求的res除200(实际以后端同事定好的为准)成功外的其他code需要额外写抛错提示 resolve(res.data) // 成功 }, // 这里的接口请求,如果出现问题就输出接口请求失败的msg; // 注:因为这里对于请求失败的设置统一抛错提示了,所以后续具体组件中使用接口请求的catch中不需要再写抛错提示 fail: (err) => { if (err.statusCode === 424) { //自定请求失败的情况,这里以常见的token失效或过期为例 store.dispatch( 'LogOut' ).then(() => { uni.showModal({ showCancel: false , title: '提示' , content: '令牌状态已过期,请点击重新登录' , success: function (result) { if (result.confirm) { uni.reLaunch({ url: '/pages/tabBar/self/self' }); } } }); }) return } uni.showToast({ title: "" + err.msg, icon: 'none' }); reject(err) } }) // #endif |
//uniapp使用条件编译#ifdef(跨平台设备兼容) // #ifdef MP-ALIPAY //获取支付宝code my.getAuthCode({ scopes: 'auth_user' , success: loginRes => { console.log(loginRes, 'ppp' ) //统一登录接口 this .login(loginRes.authCode).then(res => { uni.hideLoading(); uni.showToast({title: "登录成功" , icon: "success" }); this .getAreaList() }). catch (err => { uni.hideLoading(); }) }, fail: res => { uni.hideLoading(); uni.showToast({title: "支付宝登录授权失败" , icon: "none" }); } }); //#endi  |

样式兼容
支付宝小程序 直接在自定义组件上设置样式无效
外面包一层view 设置class处理
上架成功后注意查看是否允许被搜索