50

「小程序JAVA实战」小程序和后台api通信(28)

 5 years ago
source link: http://idig8.com/2018/08/19/xiaochengxujavashizhanxiaochengxuhehoutaiapitongxin28/?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

开发最重要的就是实操!

小程序和后台api通信

  • 小程序不能直接访问后台接口必须通过请求的方式
  • 通过内网穿透实现暴露到公网
  • ngrok ngrok.com

如何使用内网穿透

  • 登录ngrok网站

    >https://ngrok.com

URryUfF.png!web

  • 介绍

    >用户直接穿透防火墙,到云端做到互相的访问。

MbENVnn.png!web

  • 如何使用

    >注册

U36fqu3.png!web

vyMBB3V.png!web

IvqMRnV.png!web

下载ngrok

e6fEVjM.png!web

UzEN32i.png!web

7fIBvyZ.png!web

A3qiqye.png!web

当前文件夹cmd执行命令

JZR3Ib2.png!web

Nb6BJnb.png!web

启动命令,显示online,说明内网穿透成功。

#ngrok http 指定端口
ngrok http 8080

yUnMzqY.png!web

request

 https://developers.weixin.qq.com/miniprogram/dev/api/network-request.html 

jyay6rV.png!web

wx.request({
  url: 'test.php', //仅为示例,并非真实的接口地址
  data: {
     x: '' ,
     y: ''
  },
  header: {
    'content-type': 'application/json' // 默认值
  },
  success: function(res) {
    console.log(res.data)
  }
})

标准的ajax请求,跟咱们之前的jquery基本是一样的,我就不详细说了,就是获取参数的传递。但是小程序内部也封装了很多东西,后面一起实战的时候一起来说。

PS:下一章节开始实战学习,从数据库的表开始设计。

百度未收录

>>原创文章,欢迎转载。转载请注明:转载自IT人故事会,谢谢!

>>原文链接地址:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK