- 转发群可以获取openGId,那位大神知道如果转发单聊(即个人)能获取到什么?
转发群可以获取openGId,请问那位大神知道如果转发单聊(即个人)能获取到什么?我们现在有个这样的需求,求解,谢谢
2018-08-17 - 为什么我用了wx.getShareInfo返回解密后没有openGId
为什么我用了wx.getShareInfo返回解密后没有openGId,只有如下json {"openId":null,"nickName":null,"gender":null,"city":null,"province":null,"country":null,"avatarUrl":null,"unionId":null,"watermark":{"appid":"XXX","timestamp":"1534411759"}} app.js代码如下 App({ onLaunch: function (options) { //this.checkLogin(options.shareTicket); this.globalData.shareInfo = null; if (options.scene == 1044) { that.getShareInfo(options.shareTicket); } }, onShow: function (options) { this.checkLogin(options.shareTicket); }, checkLogin: function (shareTicket) { var that = this; wx.checkSession({ success: function () { if (!that.globalData.session) { that.login(shareTicket); } else { if (shareTicket) { that.getShareInfo(shareTicket); } }; }, fail: function () { that.login(shareTicket); } }) }, //登录 login: function (shareTicket) { var that = this wx.login({ success: function (r) { if (r.code) { that.decodeSession(r.code, shareTicket); } wx.getUserInfo({ success: function (res) { that.globalData.userInfo = res.userInfo; } }) } }) }, //解密session信息 decodeSession: function (code, shareTicket) { var that = this; wx.request({ url: 'https://weixin.wlstock.com/Haogudao/GetOpenIdByCode',//向后端发起换取session_key请求的URL data: { code: code }, success: function (re) { if (re.data != null && re.data.openid != null && re.data.openid != '') { that.globalData.session = { openid: re.data.openid, key: re.data.session_key }; if (shareTicket) { that.getShareInfo(shareTicket); } } else { that.globalData.session = null; } }, fail: function (res) { console.log(res); } }) }, //获取群信息 getShareInfo: function (shareTicket) { var that = this; console.log('去获取getShareInfo'); wx.getShareInfo({ shareTicket: shareTicket, success: function (res) { console.log('去获取shareinfo'); wx.request({ url: that.globalData.APIUrl +'/DataHandle/Decrypt',//向后端发起解密请求的URL data: { encryptStrOfBase64: res.encryptedData, encryptSessionKey: that.globalData.session.key, iv: res.iv }, success: function (re) { console.log('shareInfo'); console.log(re); /* var msg = ''; if (re.data.Status == 0) { that.globalData.shareInfo = JSON.parse(re.data.Data); msg = '来自群转发'; } else { that.globalData.session = null; msg = re.data.Message; } wx.showToast({ title: msg, duration: 5000 }) */ } }) }, fail: function (res) { console.log('fail'); console.log(res.errMsg); wx.showToast({ title: 'fail:' + res.errMsg, duration: 5000 }) } }); }, globalData: { userInfo: null, session: null, shareInfo: null, APIUrl: "https://XXX" } }) index.js代码如下 var app = getApp() Page({ data: { ShIndex:"", UpColor:"#04B235", IconImg:"icon-down" }, onShow: function () { var that = this; //wx.showToast({ title: '加载中', icon: 'loading', duration: 10000 })//设置加载模态框 that.GetShIndex(function (d) {//回调函数,根据数据设置页面data,更新到视图 //wx.hideToast();//隐藏加载框 console.log(d.data); console.log(app.globalData.userInfo) var upcolor = "#04B235"; var iconImg = "icon-down"; if (d.data.UpRatio>=0) { upcolor = "#f02f2f"; iconImg = "icon-up"; } that.setData({ ShIndex: d.data, UpColor: upcolor, IconImg:iconImg })//更新数据,视图将同步更新 }) }, onLoad: function() { wx.showShareMenu({ withShareTicket: true }); }, //转发 onShareAppMessage: function () { return { title: '转发小帮来猜', path: '/pages/index/index', success: function (res) { // 转发成功 var shareTickets = res.shareTickets; var shareTicket = shareTickets; wx.getShareInfo({ shareTicket: shareTicket, success: function (res) { console.log('success'); console.log(res); //console.log(res); wx.showToast({ title: '转发成功', duration: 5000 }) }, fail: function (res) { console.log('fail'); console.log(res); wx.showToast({ title: 'fail:' + res.errMsg, duration: 5000 }) } }); }, fail: function (res) { // 转发失败 } } } , GetShIndex: function (fn) { wx.request({//请求服务器,类似ajax url: app.globalData.APIUrl + '/DataHandle/GetSZIndex', data: { roundId: 0},//和风天气提供用户key,可自行注册获得 header: { 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8' }, success: function (res) { console.log(res.data); console.log(app.globalData.openId); fn(res.data); }//成功后将数据传给回调函数执行 }) } })
2018-08-16 - 求大神帮忙,获取不了openid
小程序app.js wx.login({ success:res=>{ console.log(res.code); } }) 用以上的res.code通过服务端获取openid报{"errcode":41008,"errmsg":"missing code, hints: [ req_id: rn6PNA0941hc52 ]"} 以下是c#的服务端代码 public string GetOpenIdByCode(string code) { string html = string.Empty; string url = "https://api.weixin.qq.com/sns/jscode2session?appid=XXX&secret=XXX&code=" + code + "&grant_type=authorization_code"; HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url); request.Method = "GET"; request.ContentType = "text/html;charset=UTF-8"; HttpWebResponse response = request.GetResponse() as HttpWebResponse; Stream ioStream = response.GetResponseStream(); StreamReader sr = new StreamReader(ioStream, Encoding.UTF8); html = sr.ReadToEnd(); sr.Close(); ioStream.Close(); response.Close(); return html; }
2018-08-10 - 在globalData定议了属性但读取的时候问题是报错
app.js globalData: { userInfo: null, APIUrl:"aaaa" } --------------------------------------------- index.js var app = getApp() Page({ data: { }, onLoad: function() { var dd = app.gloabData.APIUrl; console.log('123'+dd); }, }) ------------------------------------ 总是报: VM89:1 thirdScriptError Cannot read property 'APIUrl' of undefined;at pages/index/index page lifeCycleMethod onLoad function TypeError: Cannot read property 'APIUrl' of undefined
2018-08-08 - 如果保存历史访客头像和昵称?
在小程序准备做一个最近访客列表,列表要显示最近访客的头像、昵称,不知道如何做,我在想:是首先保存访客的openid,根据openid获取该访客的头像?但用那个接口呢?又或者先保存每个访客的头像,之后读出来?麻烦各位大神帮帮忙
2018-08-07