merging
This commit is contained in:
@@ -1,24 +1,24 @@
|
||||
var weRequest = require('../src/weRequest');
|
||||
|
||||
weRequest.init({
|
||||
// 存在localStorage的session名称,且CGI请求的data中会自动带上以此为名称的session值;可不传,默认为session
|
||||
// 存在localStorage的session名称,且CGI请求的data中会自动带上以此为名称的session值;可不配置,默认为session
|
||||
sessionName: "session",
|
||||
// 请求URL的固定前缀;可不传,默认为空
|
||||
urlPerfix: "https://payapp.weixin.qq.com/",
|
||||
// 请求URL的固定前缀;可不配置,默认为空
|
||||
urlPerfix: "https://www.example.com/",
|
||||
// 触发重新登录的条件,res为CGI返回的数据
|
||||
loginTrigger: function (res) {
|
||||
// 此处例子:当返回数据中的字段errcode等于0x10040009,会自动触发重新登录
|
||||
return res.errcode == 0x10040009;
|
||||
// 此处例子:当返回数据中的字段errcode等于-1,会自动触发重新登录
|
||||
return res.errcode == -1;
|
||||
},
|
||||
// 用code换取session的CGI配置
|
||||
codeToSession: {
|
||||
// CGI的URL
|
||||
url: 'user/login',
|
||||
// 调用改CGI的方法;可不传,默认为GET
|
||||
// 调用改CGI的方法;可不配置,默认为GET
|
||||
method: 'GET',
|
||||
// CGI中传参时,存放code的名称,此处例子名称就是code;可不传,默认值为code
|
||||
// CGI中传参时,存放code的名称,此处例子名称就是code;可不配置,默认值为code
|
||||
codeName: 'code',
|
||||
// 登录接口需要的其他参数;可不传,默认为{}
|
||||
// 登录接口需要的其他参数;可不配置,默认为{}
|
||||
data: {},
|
||||
// CGI中返回的session值
|
||||
success: function (res) {
|
||||
@@ -36,7 +36,7 @@ weRequest.init({
|
||||
// 此处例子:当返回数据中的字段errcode等于0时,代表请求成功,其他情况都认为业务逻辑失败
|
||||
return res.errcode == 0;
|
||||
},
|
||||
// 成功之后返回数据;可不传
|
||||
// 成功之后返回数据;可不配置
|
||||
successData: function (res) {
|
||||
// 此处例子:返回数据中的字段data为业务接受到的数据
|
||||
return res.data;
|
||||
@@ -55,9 +55,9 @@ weRequest.init({
|
||||
errorCallback: function(obj, res) {
|
||||
// do some report
|
||||
},
|
||||
// 是否需要调用checkSession,验证小程序的登录态过期,可不传,默认为false
|
||||
// 是否需要调用checkSession,验证小程序的登录态过期,可不配置,默认为false
|
||||
doNotCheckSession: true,
|
||||
// 上报耗时的函数,name为上报名称,cost为耗时
|
||||
// 上报耗时的函数,name为上报名称,startTime为接口调用开始时的时间戳,endTime为接口返回时的时间戳
|
||||
reportCGI: function(name, startTime, endTime, request) {
|
||||
//wx.reportAnalytics(name, {
|
||||
// time: endTime - startTime
|
||||
@@ -74,12 +74,14 @@ weRequest.init({
|
||||
//})
|
||||
console.log(name + ":" + (endTime - startTime));
|
||||
},
|
||||
// 提供接口的mock,若不需使用,请设置为false
|
||||
mockJson: require("../../mock.json"),
|
||||
globalData: function() {
|
||||
// 所有请求都会自动带上globalData里的参数
|
||||
globalData: function() {
|
||||
return {
|
||||
version: getApp().version
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
module.exports = weRequest;
|
||||
module.exports = weRequest;
|
||||
|
||||
Reference in New Issue
Block a user