微信小程序wx.request封装
2018/01/09
function __args() {
var setting = {};
if (arguments.length === 1 && typeof arguments[0] !== 'string') {
setting = arguments[0];
} else {
setting.url = arguments[0];
if (typeof arguments[1] === 'object') {
setting.data = arguments[1];
setting.success = arguments[2];
} else {
setting.success = arguments[1];
}
}
if (setting.url.indexOf('https://') !== 0) {
setting.url = 'https://wxapp.im20.com.cn' + setting.url;
}
return setting;
}
function __json(method, setting) {
setting.method = method;
setting.header = {
'content-type': 'application/json'
};
wx.request(setting);
}
module.exports = {
getJSON: function () {
__json('GET', __args.apply(this, arguments));
},
postJSON: function () {
__json('POST', __args.apply(this, arguments));
},
sendTemplate: function(formId, templateData, success, fail) {
var app = getApp();
this.getJSON({
url: '/WxAppApi/sendTemplate',
data: {
rd_session: app.rd_session,
form_id: formId,
data: templateData,
},
success: success, // errorcode==0时发送成功
fail: fail
});
}
}
上一篇:
屏幕宽度适应及懒加载
下一篇:
vscode连接tfs
静水缘首页
文章分类
最新文章
- nodejs私钥加密公钥解密的一个例子
- uniapp和微信小程序判断程序运行在开发或者测试或者线上版本的方法分别是什么
- electron使用electron-builder打包后模块包含exe文件执行失败
- Compile is disallowed on the main thread, if the buffer size is larger than 4KB
- better-sqlite3简介及常用操作
- nodejs 操作数据库的库
- nodejs使用http-proxy库实现多个域名代理和同时代理websocket的例子,代理包含https和http两种协议
- iis配置反向代理
- javascript伪多线程代码
- ip所在地址段判断