小程序开发注意事项

2017-06-28  本文已影响0人  张辰云

小程序开发注意事项

小程序分享

  1. 微信小程序的分享只能分享到朋友 不能分享到朋友圈
  2. 微信小程序的分享可以指定分享页面, 并带参数值

onShareAppMessage(options)

在 Page 中定义 onShareAppMessage 函数,设置该页面的转发信息。

options 参数说明

参数 类型 说明
from String 转发事件来源。button:页面内转发按钮;menu:右上角转发菜单
target Object 如果 from 值是 button,则 target 是触发这次转发事件的 button,否则为 undefined

自定义转发字段

字段 说明 默认值 最低版本
title 转发标题 当前小程序名称
path 转发路径 当前页面 path ,必须是以 / 开头的完整路径
success 转发成功的回调函数 1.1.0
fail 转发失败的回调函数 1.1.0
complete 转发结束的回调函数(转发成功、失败都会执行 1.1.0

回调结果:

回调类型 errMsg 说明
success shareAppMessage:ok 转发成功
fail shareAppMessage:fail cancel 用户取消转发
fail shareAppMessage:fail (detail message) 转发失败,其中 detail message 为详细失败信息

success回调参数说明:

参数 类型 说明 最低版本
shareTickets StringArray shareTicket 数组,每一项是一个 shareTicket ,对应一个转发对象 1.1.0

代码示例

Page({
  onShareAppMessage: function (res) {
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    return {
      title: '自定义转发标题',
      path: '/page/user?id=123', // 该链接可指定分享出去页面打开的链接 并以get参数的写法传递参数 
      success: function(res) {
        // 转发成功
      },
      fail: function(res) {
        // 转发失败
      }
    }
  }
})

接收的写法

Page({
 onLoad:function(options){ // 分享过来的页面的参数会传递到 onload 函数 以 options 变量的形式传递进来
   console.log(options); // 打印出分享过来传递的参数
 }
})

分享后拿值的注意点

生成二维码

https 加密配置须知

其他资料

nginx 配置代理

nginx的示例代码

nginx 做代理 代理 http https

本架构是 所有访问由nginx 进行分发 转发到后台的各服务器再进行处理

server
{
  listen 80;
  server_name wxxcx.hbbettercell.com;
  location / {
    proxy_pass http://172.20.10.40;
        proxy_cache off;
        proxy_cache_valid 200 302 1d;
        proxy_cache_valid 301 30d;
        proxy_cache_valid any 5m;
        proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
  }
  access_log logs/wxxcx.access.log;
  expires 30d;
}
server
{
  listen 443;
  server_name wxxcx.hbbettercell.com;
  ssl on;
  ssl_certificate wxxcx.hbbettercell.com.pem;
  ssl_certificate_key wxxcx.hbbettercell.com.key;
  location / {
    proxy_pass https://172.20.10.40:443;
        proxy_cache off;
        proxy_set_header Host $host:443;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Via "nginx";
        proxy_cache_valid 200 302 1d;
        proxy_cache_valid 301 30d;
        proxy_cache_valid any 5m;
        proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
  }
  access_log logs/wxxcx.access.log;
  expires 30d;
}
上一篇 下一篇

猜你喜欢

热点阅读