<web-view src="https://你的C2页面地址/index.html?参数=值"></web-view>
onShareAppMessage: function (res) { return { title: '分享标题', desc: '分享描述', imageUrl: '分享用图片', //长宽比5:4,可以拷贝到index目录下 比如'/pages/index/share.png' path: '分享路径' //如果没有别的选项就是'/pages/index/index' } }
找到 app.json 在“window”下加上
"navigationStyle": "custom"
注意JSON格式,即可实现全屏,另外注意,调试基础库版本需高于1.9.4,此命令才有效
微信登录需要后端支持 在默认模板的 app.js 中有示例代码
wx.login({ success: res => { // 发送 res.code 到后台换取 openId, sessionKey, unionId } })
改成
wx.login({ success: res => { // 发送 res.code 到后台换取 openId, sessionKey, unionId if (res.code) { var that = this wx.request({ url: 'https://LOGIN_REQUEST_URL/', data: { code: res.code }, success: function (result) { let openId = result.data.openid; wx.setStorageSync('openid', openId) if (this.userOpenidCallback) { this.userOpenidCallback(result) } } }) } else { console.log('ERR' + res.errMsg); } } })
这样之后就可以在本地缓存中取出openid,对应后端代码如下:
<?PHP header("Access-Control-Allow-Origin: *"); $appid = "YOUR_APPID"; $secret = "YOUR_APPSECRET"; @$code = $_REQUEST["code"]; $url = "https://api.weixin.qq.com/sns/jscode2session?appid=$appid&secret=$secret&js_code=$code&grant-type=authorization_code"; $res = getcurl($url); $arr = json_decode($res, true); //$openid = $arr["openid"]; print_r($res); exit();
由于微信修改了策略,必须要点击按钮才允许获取用户信息,所以之前打算在打开页面时直接获取用户信息的计划就可以拜拜了,在默认模板项目 index.js 中,有如下代码
getUserInfo: function(e) { console.log(e) app.globalData.userInfo = e.detail.userInfo this.setData({ userInfo: e.detail.userInfo, hasUserInfo: true }) }
改为
getUserInfo: function (e) { console.log(e) app.globalData.userInfo = e.detail.userInfo this.setData({ userInfo: e.detail.userInfo, hasUserInfo: true }); wx.request({ url: 'https://INFO_REQUEST_URL', data: { openid: wx.getStorageSync('openid'), info: app.globalData.userInfo } }) }
执行这一步的目的,是为了将UserInfo传递到后端进行保存,便于在C2页面中用AJAX取得Userinfo,对应的后端需要用数据库(Redis或MySQL)保存上传的Userinfo,以openid为标识Key,存储数据,代码如下:
<?PHP $redis = new Redis(); $redis->connect('REDIS_HOST', 'REDIS_PORT'); $redis->auth('REDIS_AUTH'); @$info = $_REQUEST["info"]; @$oid = $_REQUEST["openid"]; $redis->hset("userinfo", $oid, $info); $redis->close(); exit();
之后在C2中用AJAX再取数据时,直接用openid从redis中取值即可,如
echo $redis->hget("userinfo",$oid);