// 封装gat
function get(url,date,res){
wx.request({
url: url, //仅为示例,并非真实的接口地址
data: date,//数据格式{'name':1,'xx':2}
header: {'content-type': 'application/json'},// 默认值get,
method:'get',
dataType:"json",
responseType:"text",
success (e) {
res(e);
},
fail: ()=>{
wx.showToast({
title: '系统繁忙,请联系管理员',
icon: 'none',
duration: 2000
})
}
})
}
// 封装post
function post(url,date,res){
wx.request({
url: url, //仅为示例,并非真实的接口地址
data: date,//数据格式{'name':1,'xx':2}
header: { "Content-Type": "application/x-www-form-urlencoded"},//post
method:'post',
dataType:"json",
responseType:"text",
success (e) {
res(e)
},
fail: ()=>{
wx.showToast({
title: '系统繁忙,请联系管理员',
icon: 'none',
duration: 2000
})
}
})
}
var _this = this;
// 登录
function name_login(url,openid,e){
wx.getUserProfile({
desc: '用于完善会员资料',
success: (res) => {
wx.setStorage({
key:"name_login",
data:res.userInfo
})
var data = {'equipment':1,'appid':'111','openid':openid,"user":res.userInfo.nickName,'img':res.userInfo.avatarUrl};
var urls = url+"/wxapp/add";
post(urls,data,es=>{
console.log(es)
if(es.data.message == "添加成功"){
var da = es.data.data;
}else{
//用户已存在
var da = es.data.data[0];
}
wx.setStorage({
key:"username",
data:da
})
})
e(res)
}
})
}
// 使用
// const app = getApp()
// var http = require("../../utils/http/https")
// var url = app.globalData.apphttp+"/wxapp/1";
// http.get(url,1,res=>{
// console.log(res)
// })
module.exports = {
get,
post,
name_login,
}