微信小程序----编写后台服务接口配置文件
2018-05-23 16:40
453 查看
微信小程序----编写后台服务接口配置文件
编写后台服务接口配置文件
const basePath = 'http://test.cdbhbc.com/wbgapi'; const urlList = { // 刷新token refreshTokeUrl: basePath + '/refreshToke',//token // 登录和首页轮播 loginUrl: basePath + '/wxappLogin',//登录 advertPicListUrl: basePath + '/advertPicList',//轮播列表 // 网吧 shopSortListUrl: basePath + '/shopSortList',//网吧分类列表 shopListUrl: basePath + '/shopList',//网吧列表 shopDetailUrl: basePath + '/shopDetail',//网吧详情 // 商品 goodsSortListUrl: basePath + '/goodsSortList',//商品分类列表 goodsListUrl: basePath + '/goodsList',//商品列表 goodsDetailUrl: basePath + '/goodsDetail',//商品详情 // 订单 orderListUrl: basePath + '/orderList',//订单列表 orderDetailUrl: basePath + '/orderDetail',//订单详情 payBeforeInfoUrl: basePath + '/payBeforeInfo',//订单支付前信息 submitOrderUrl: basePath + '/submitOrder',//提交订单 // 购物车 emptyShopCartUrl: basePath + '/emptyShopCart',//清空购物车 addShopCartUrl: basePath + '/addShopCart',//添加到购物车 shopCartListUrl: basePath + '/shopCartList',//购物车列表 // 修改商品数量 shopCartBuyCountOperateUrl: basePath + '/shopCartBuyCountOperate',//修改商品数量 // 支付 wxPayUrl: basePath + '/wxPay/payConfig',//支付信息接口 // 特殊商品网费 goodsSpecialDetailUrl: basePath + '/goodsSpecialDetail',//网费充值列表 submitSpecialOrderUrl: basePath + '/submitSpecialOrder',//网费充值提交 // 我的网吧 shopMyListUrl: basePath + '/shopMyList',//我的网吧列表 shopMyAddUrl: basePath + '/shopMyAdd',//添加我的网吧 } module.exports = urlList;
接口配置文件的使用
// 引入配置文件config const urlList = require('../../utils/config.js'); // request请求的时候使用,实例:更新token接口的使用 App({ refreshToke(){ // 小程序登录接口获取code wx.login({ success: res => { // console.log(res) if(res.errMsg == 'login:ok'){ //调用refreshTokeUrl接口刷新token wx.request({ url: urlList.refreshTokeUrl, data: { code: res.code }, success: res => { // console.log(res) if(res.data.state == 'true'){ // token本地存储并且进行全局变量的赋值 wx.setStorageSync('token', res.data.data.token); this.globalData.token = res.data.data.token; } } }) } } }) } })
接口配置文件的作用
- 在项目开发时能够在固定位置很快查到需要的接口;
- 服务器地址改变时,只用替换 basePath 的值,就能全部替换,不用去单独页面替换;
- 方便接口的集中管理,方便后期的维护。
DEMO下载
posted @ 2018-05-23 16:40 Newman·Li 阅读(...) 评论(...) 编辑 收藏相关文章推荐
- 微信小程序,腾讯云node环境后台koa2开发框架(本地调试、接口、静态文件服务、文件长传服务)
- 小程序调用后端接口服务 配置文件详解
- 小程序调用后端接口服务 配置文件详解
- 监听总结之解析问题一:由sqlnet.ora文件寻到TNSNAME适配器程序来解析网络服务名为它的具体配置(×)
- 使用Visual Studio 2008编写后台服务程序
- SpringCloud系列:服务配置文件的进化历程(程序内置、程序外置、实时更新)
- 编写一个带管理界面(对话框)的windows后台服务程序
- 原创:微信小程序调用PHP后台接口,解析纯html文本
- idea编写hibernate程序时找不到**hmb.xml配置文件
- Qt编写Android程序中添加XML配置文件
- 微信小程序配置文件 .json详解
- 微信小程序调用PHP后台接口 解析纯html文本
- 小程序web-view JSSDK配置文件说明——微信web-view高级用法4
- C# 做微信小程序后台,基本服务器配置 以及 图片上传
- 使用Typescript ansyc 编写微信小程序文件上传
- WINDOWS后台服务程序编写
- 微信接口后台开发与配置
- 编写WCF服务时右击配置文件无“Edit WCF Configuration”(编辑 WCF 配置)远程的解决办法
- WCF 服务器CONFIG文件(用服务配置编辑器编写)
- 微信小程序语音识别服务搭建全过程解析(https api开放,支持新接口mp3录音、老接口silk录音)