import {
apiBaseUrl,
jhghUrl,
apiSalt,
userCheckList,
jhghUrlrenzheng
} from ‘@/common/config.js’;
import * as sign from ‘@/common/sign.js’
import md5 from ‘@/js/md5.js’

//封装请求
const request = (url = ‘’, date = {}, type = ‘post’, header = {
‘content-type’: ‘application/x-www-form-urlencoded’,
}) => {
return new Promise((resolve, reject) => {
//统一验签
let thistime = sign.timestamp()
date.timestamp = thistime
date.sign = md5(apiSalt + thistime).toUpperCase()
//不在白名单中,需要加openid的url
if(!userCheckList.find(item=>item==url)){
//不需验证的方法也可传,需要验的也可以为空
date.openid = uni.getStorageSync(‘openid’)
date.token = uni.getStorageSync(‘token’)
}
uni.request({
method: type,
url: apiBaseUrl + url,
data: date,
header: header,
dataType: ‘json’,
}).then((response) => {
setTimeout(function() {
uni.hideLoading();
}, 200);
let [error, res] = response;
// 无用户信息
if (res.data.code == 9999) {
/*
uni.showModal({
title:‘提示’,
content: res.data.msg,
confirmText: “重新获取”,//这块是确定按钮的文字
cancelText:“关闭”,//这块是取消的文字
success: function(res) {
if (res.confirm) {//重新获取 返回主程序
window.location.href=jhghUrl
} else if (res.cancel) {//彻底退出
weixinClosePage()
}
}
});
*/
//延迟跳转时间
// window.setTimeout(function(){ window.location.href=jhghUrl } ,2000);
window.location.href=jhghUrl

     //购买过一单,直接退出}else if(res.data.code==8888){alert(res.data.msg) //提示退出weixinClosePage()}//用户未认证// else if(res.data.code==7777){//  // alert(res.data.msg) 示退出//    uni.showModal({//       title:'提示',//         content: res.data.msg+uni.getStorageSync('openid')+"::"+uni.getStorageSync('token'),//         confirmText: "去认证",//这块是确定按钮的文字//         cancelText:"关闭",//这块是取消的文字//      success: function(res) {//          if (res.confirm) {//去认证  返回主程认证//            window.location.href=jhghUrlrenzheng//            } else if (res.cancel) {//彻底退出//                weixinClosePage()//             }//         }//     });// }else{resolve(res.data);}}).catch(error => {// alert(error)uni.showToast({title:"您网络不佳,请下拉刷新",icon:'none',duration: 1500})let [err, res] = error;reject(err)})
});

}

function weixinClosePage() {
document.addEventListener(‘WeixinJSBridgeReady’, function(){ WeixinJSBridge.call(‘closeWindow’); }, false)
if (typeof WeixinJSBridge == “undefined”) {
if (document.addEventListener) {
document.addEventListener(‘WeixinJSBridgeReady’,weixin_ClosePage1(), false);
} else if (document.attachEvent) {
document.attachEvent(‘WeixinJSBridgeReady’, weixin_ClosePage1());
document.attachEvent(‘onWeixinJSBridgeReady’, weixin_ClosePage1());
}
} else {
weixin_ClosePage1();
}
}
function weixin_ClosePage1() {
window.WeixinJSBridge.call(‘closeWindow’);
}

export default request

uniapp封装请求(包含白名单、验签)相关推荐

  1. nginx设置IP、文件目录、请求头白名单

    1.重点 2.测试环境 3.设置IP白名单 禁止多个ip 4.禁止访问某个目录 路径匹配符号 5.禁止访问某个目录的单个文件 6.请求头白名单 7.设置对应响应码的返回页面 1.重点 location ...

  2. php接口增加白名单,使用laravel中间件来添加指定请求的白名单

    这件事的需求是这样: 我们使用微信公众平台的开发模式搭建好了一个后台,这样就不得不把运营人员设置的关键词回复加进来.当然我们不希望每次运营人员想修改时,都让我们来直接改代码.于是我就为他们写了个关键词 ...

  3. iOS 对https App内部的http请求进行白名单设置

    苹果从iOS9开始要求应用使用Https链接来对请求进行加密,来保证数据的安全.如果使用http请求将会报错,当然,如果你想继续使用http请求,有两种方式: 1.使用ASIHttpRequest来请 ...

  4. 微信小程序/uni-app 封装请求

    utils>http>http.js文件 一层封装请求 //post和get请求封装 const baseUrl = "XXXXXXXXX"; // 测试环境 cons ...

  5. uni-app封装请求方法与api封装调用

    1.封装请求创建request.js文件,把一下内容根据自己的需求更改. //封装请求方法 //声明一个请求函数 const api_request=(url, method, parm)=>{ ...

  6. uni-app封装请求方法和loading样式

    // 接口请求域名 const baseUrl = 'http://192.168.1.20:8080/' // 同时发送异步代码的次数,防止一次点击中有多次请求 let ajaxTimes=0; / ...

  7. uniapp封装请求的方法(luch-request插件使用)

    1.安装luch-request npm i luch-request -S 2.设置根地址 新建一个baseUrl目录 ,设置一个url.js //基础Api const BASE_API=&quo ...

  8. uni-app封装请求出现跨域问题

    配置uni-app 中 manifest.json->h5->devServer manifest.json "h5" : {"devServer" ...

  9. uni-app 封装请求

    1.npm install uni-request --save 2.uniRequest.defaults.baseURL = '请求路径基地址': 3.uniRequest.defaults.he ...

最新文章

  1. mysql 哨兵模式_Redis讲解主从复制和哨兵模式
  2. JCO连接SAP例子
  3. 关于Scrum中sprint的规模估算的对话
  4. 没有上下文的java类_java – 这个上下文中没有任何一个超级类
  5. K个一组翻转链表—leetcode25
  6. 【CF global1 D / CF1110D】 Jongmah
  7. mysql三-3:完整性约束
  8. javascript中打印对象显示[object object]_js如何打印object对象
  9. lua 给userdata设置元表_UE4热更新:基于UnLua的Lua编程指南
  10. 【实践】Angel深度学习在广告推荐训练优化中的实践.pdf(附下载链接)
  11. GoldWave的消音、淡入淡出、改变音乐速率
  12. Java集合框架总结
  13. MATLAB常用画图命令汇总【已坑】
  14. 单片机开发系列(一)之Keil 5 安装使用教程
  15. SQL列转行问题(踩雷)
  16. codeBlock调试技巧
  17. 在淘宝,我如何做好一个项目的启动?
  18. 28岁程序员从字节退休:IT是改命的唯一出路吗?
  19. crontab命令不执行
  20. 35岁的程序员:第16章,双重担忧

热门文章

  1. 云呐|医疗医院固定资产设备管理如何高效管理
  2. (一)Android音视频-视频编解码
  3. 网站备案所需准备材料
  4. 【程序设计】CSV必知必会
  5. nginx 日志解析
  6. RAID5的配置流程及模拟硬盘损坏
  7. sql2008 新建登录用户只能修改某一个表 服务器角色,sql语句创建新登录名和设置权限...
  8. vscode变假期不提示_12个假期的家庭技术支持提示
  9. 如何分析出网站关键字
  10. 在QGIS 3.10中访问Geoserver中发布的服务