求解
小程序getPhoneNumber 解密手机号时,偶尔会出现填充无效,无法被移除客户端 getPhoneNumber: function (e) { let that=this; wx.login({ success: function (res) { if (e.detail.errMsg == 'getPhoneNumber:fail user deny') { wx.navigateTo({ url: '../../pages/userLogin/userLogin', }); } else { if (e.detail.errMsg == 'getPhoneNumber:fail:cancel to confirm login') { wx.navigateTo({ url: '../../pages/userLogin/userLogin?url='+that.data.url }); } else { //console.log(res.code); wx.request({ url: api.AESdecrypt, data: { 'encryptedDataStr': e.detail.encryptedData, 'code': res.code, 'iv': e.detail.iv }, method: 'post', header: { 'content-type': 'application/x-www-form-urlencoded' }, success: function (data) { console.log(data); app.globalData.userInfo = data.data.data; setTimeout(function(){ wx.navigateBack({ changed: true });//返回上一页 },500); }, error: function () { tip.showToast('error'); }, fail: function (err) { tip.showToast(err); } }) } } } }); }, 服务端 try { string encryptedDataStr = System.Web.HttpContext.Current.Request["encryptedDataStr"], code = System.Web.HttpContext.Current.Request["code"], iv = System.Web.HttpContext.Current.Request["iv"]; ReturnData resultMsg = new ReturnData(); resultMsg.state = (int)StatusCodeEnum.Success; resultMsg.message = StatusCodeEnum.Success.GetEnumText(); string strresult = ""; string Appid = "Appid"; string Secret = "Secret "; string grant_type = "authorization_code"; GetUsersHelper GetUsersHelper = new Controllers.GetUsersHelper(); //向微信服务端 使用登录凭证 code 获取 session_key 和 openid string url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + Appid + "&secret=" + Secret + "&js_code=" + code + "&grant_type=" + grant_type; Stream s_re = WebRequest.Create(url).GetResponse().GetResponseStream(); StreamReader sr = new StreamReader(s_re, Encoding.UTF8); string strLine = sr.ReadToEnd(); sr.Close(); //将字符串转换为json格式 JObject jo = (JObject)JsonConvert.DeserializeObject(strLine); result res = new result(); try { //微信服务器验证成功 res.openid = jo["openid"].ToString(); res.session_key = jo["session_key"].ToString(); } catch (Exception) { //微信服务器验证失败 res.errcode = jo["errcode"].ToString(); res.errmsg = jo["errmsg"].ToString(); WriteInfo(res.errmsg); } if (!string.IsNullOrEmpty(res.openid)) { //用户数据解密 strresult = GetUsersHelper.AESDecrypt(encryptedDataStr, res.session_key,iv);//.AES_decrypt(encryptedDataStr,res.session_key,iv);// JObject jos = (JObject)JsonConvert.DeserializeObject(strresult); ResultInfo ress = new ResultInfo(); ress.phoneNumber = jos["phoneNumber"].ToString(); var model = Ioc.Get<IUserRepository>().FindMobile(ress.phoneNumber); resultMsg.data = model; } else { strresult = null; resultMsg.data = strresult; } return resultMsg; } catch (Exception ex) { WriteInfo(ex.Message); return new ReturnData { state=200, message="error", data=null }; } 解密.net public string AESDecrypt(string inputdata, string AesKey, string AesIV) { try { RijndaelManaged rijalg = new RijndaelManaged(); //----------------- //设置 cipher 格式 AES-128-CBC rijalg.KeySize = 128; rijalg.Padding = PaddingMode.PKCS7; rijalg.Mode = CipherMode.CBC; rijalg.Key = Convert.FromBase64String(AesKey); rijalg.IV = Convert.FromBase64String(AesIV); byte[] encryptedData = Convert.FromBase64String(inputdata); //解密 ICryptoTransform decryptor = rijalg.CreateDecryptor(rijalg.Key, rijalg.IV); string result; using (MemoryStream msDecrypt = new MemoryStream(encryptedData)) { using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)) { using (StreamReader srDecrypt = new StreamReader(csDecrypt)) { result = srDecrypt.ReadToEnd(); } } } return result; } catch (Exception ex) { ApiUserController apis = new ApiUserController(); apis.WriteInfo("jiemi"+ex.Message); return null; } }
2018-09-29在哪里在哪里
微信小程序 订阅消息功能[图片] 请教一下官方,这个订阅消息相关的文档在哪里,我在小程序官方文档没有看到相关信息呢,只是在小程序官方示例中看到过.
2018-07-19让官方给你反编译
小程序代码怎样下载?我的公众平台小程序已经发布了,之后发现有误的地方需要更改,突然间发现电脑出现问题,把所有的数据没有了,我现在重新写很不方便,能不能我已经发布了的代码下载下来?
2018-07-03