WX smallApp

SmallApp

1.1框架结构

结构
构架

1.1.1 逻辑层

1)app.js:

App({  
  /** 
   * 当小程序初始化完成时,会触发 onLaunch(全局只触发一次) 
   */  
  onLaunch: function (options) {  
    console.log("生命周期函数--监听小程序初始化");  
    console.log(options.path);//打开小程序的路径  String  
    console.log(options.query);//打开小程序的query  Object  
    console.log(options.scene);//打开小程序的场景值  Number  
    console.log(options.shareTicket);//转发信息  String  
    console.log(options.referrerInfo);//当场景为由另一个小程序打开时,返回此字段 Object  
    console.log(options.referrerInfo.appId);//来源小程序的 appId   String  
    console.log(options.referrerInfo.extraData);//来源小程序传过来的数据  Object  
  },  
  /** 
   * 当小程序启动,或从后台进入前台显示,会触发 onShow 
   */  
  onShow: function (options) {  
    console.log("生命周期函数--监听小程序显示");  
  },  
  /** 
   * 当小程序从前台进入后台,会触发 onHide 
   */  
  onHide: function () {  
    console.log("生命周期函数--监听小程序隐藏");  
  },  
  /** 
   * 当小程序发生脚本错误,或者 api 调用失败时,会触发 onError 并带上错误信息 
   */  
  onError: function (msg) {  
    console.log("错误监听函数");  
  }  
  /** 
   * 其他自定义函数,全局变量 
   */  
  globalData:{  
    userName:"cj",  
    userAge:998  
  }   
})

2) app.json:

{  
  "pages": [//必须  
    "pages/index/index",//小程序中每增减页面,都要对这边进行增减  
    "pages/logs/index"  
  ],  
  "window": {//非必须  
    "navigationBarBackgroundColor": "#000000",//导航栏默认颜色  
    "navigationBarTextStyle": "white",//导航栏标题颜色,默认白色,仅支持黑白  
    "navigationBarTitleText": "微信接口功能演示",//导航栏文字内容  
    "backgroundColor": "#ffffff",//窗口默认背景色  
    "backgroundTextStyle": "dark",//下拉背景字体、loading图默认样式,仅支持dark/light  
    "enablePullDownRefresh":false  //是否开启下拉刷新,默认false  
  },  
  "tabBar": {//非必须,底部切换页面  
    "color":"",//必须/tab文字默认颜色  
    "selectedColor": "",//必须/tab文字选中的颜色  
    "backgroundColor": "",//必须/tab背景色  
    "borderStyle": "",//tab边框颜色,默认black,仅支持黑白  
    "position": "bottom",//图标 top的时候则不显示  
    "list": [//必须/tab列表  
      {   
        "pagePath": "pages/index/index",//必须/页面路径  
        "text": "首页",//必须/按钮文字  
        "iconPath":"",//图片路径  
        "selectedIconPath":""//选中时图片路径  
      },  
      {  
        "pagePath": "pages/logs/logs",  
        "text": "日志"  
      }  
    ]  
  },  
  "networkTimeout": {//非必须  设置网络请求时间  
    "request": 10000,//wx.request的超时时间,单位毫秒,默认为:60000  
    "connectSocket": 10000,//wx.connectSocket的超时时间,单位毫秒,默认为:60000  
    "uploadFile": 10000, //wx.uploadFile的超时时间,单位毫秒,默认为:60000  
    "downloadFile":10000 //wx.downloadFile的超时时间,单位毫秒,默认为:60000  
  },  
  "debug": true    //非必须  是否开启debug模式  
}

1.1.2 视图层


1.2 API

1.2.1 用户登录及状态维护

登录
这里写图片描述
1. 在客户端获取当前登录微信用户的登录凭证(code);
2. 将登录凭证发往你的服务端,并在你的服务端使用该凭证向微信服务器换取该微信用户的唯一标识(openid)和会话密钥(session_key)(https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code)
为安全起见,在自己服务器端使用redis(session_key和openid作为值)做一层自己的session,并设置一个超时的时间;
3. 在客户端保存sessionid:小程序没有cookie机制使用storage存储;
4. 调用那些需要登录后才有权限的访问的后台服务时,可以将保存在storage中的sessionid取出并携带在请求中,传递到后台服务,后台获取到该sessionid后,从redis中查找是否有该sessionid存在。

1.2.1 支付

支付
这里写图片描述
商户系统和微信支付系统主要交互:
1. 小程序内调用登录接口,获取到用户的openid,api参见公共api;
2. 商户server调用支付统一下单,api参见公共api;
3. 商户server调用再次签名,api参见公共api;
4. 商户server接收支付通知,api参见公共api;
5. 商户server查询支付结果,api参见公共api;


SmallGame

2.1框架结构


3服务器部署

3.1 jdk tomcat

3.2 Redis

  • yum install gcc 安装gcc (rpm -qa |grep gcc查看安装是否成功)
  • wget http://download.redis.io/releases/redis-4.0.6.tar.gz
  • tar xzf redis-4.0.6.tar.gz
  • cd redis-4.0.6
  • make编译 生成src、conf等文件夹
  • 进入src文件夹,执行make install进行Redis安装
  • ./redis-server,启动Redis服务

3.3 Mysql

tar -xvf mysql-5.7.21-linux-glibc2.12-x86_64.tar.gz /usr/local
ln -s /usr/local/mysql-5.7.21-linux-glibc2.12-x86_64 /usr/local/mysql
初始化:
cd /usr/local/mysql
mkdir mysql-files
chown -R mysql .
chgrp -R mysql .
bin/mysqld --initialize --usr=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
bin/mysql_ssl_rsa_setup
chown -R root .
chown -R mysql data mysql-files
\cp -rf support-files/my-default.cnf /etc/my.cnf
bin/mysqld_safe --user=mysql & (/etc/init.d/mysql start)
echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
souce /etc/profile
mysql -uroot -p'xxxx' (./bin/mysql -uroot -p)
alter user root@'localhost' identified by "123456";
flush privileges;

重新初始化:
killall mysqld
rm -rf /usr/local/mysql/data
chown -R mysql .
chgrp -R mysql .
bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
bin/mysql_ssl_rsa_setup
chown -R root .
chown -R mysql data mysql-files
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值