Commit 4d88c49a authored by 吴春's avatar 吴春

页面修改

parent 75117d0d
......@@ -807,6 +807,21 @@ namespace Edu.Common
get { return "wx38e054ee42b054f4"; }
}
/// <summary>
/// 甲小鹤AppId
/// </summary>
public static string JiaXiaoHeAppId {
get { return "wx0f4b451960f8ef29"; }
}
/// <summary>
/// 甲小鹤AppSecret
/// </summary>
public static string JiaXiaoHeAppSecret
{
get { return "62332ef58d16280fc05613fc61ecff1d"; }
}
/// <summary>
/// 甲鹤小程序AppSecret
/// </summary>
......
......@@ -5,6 +5,8 @@ using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using Edu.Common.Plugin;
using Newtonsoft.Json.Linq;
namespace Edu.Common
{
......@@ -695,31 +697,24 @@ namespace Edu.Common
/// <param name="iv"></param>
/// <returns></returns>
public static string AES_decrypt(string encryptedDataStr, string key, string iv)
public static string AES_decrypt(string encryptedData, string Session_key, string iv)
{
RijndaelManaged rijalg = new RijndaelManaged();
//-----------------
//设置 cipher 格式 AES-128-CBC
rijalg.KeySize = 128;
rijalg.Padding = PaddingMode.PKCS7;
rijalg.Mode = CipherMode.CBC;
rijalg.Key = Convert.FromBase64String(key);
rijalg.IV = Convert.FromBase64String(iv);
byte[] encryptedData = Convert.FromBase64String(encryptedDataStr);
//解密
ICryptoTransform decryptor = rijalg.CreateDecryptor(rijalg.Key, rijalg.IV);
string result;
using (MemoryStream msDecrypt = new MemoryStream(encryptedData))
string phoneNum = "";
byte[] encryData = Convert.FromBase64String(encryptedData); // strToToHexByte(text);
RijndaelManaged rijndaelCipher = new RijndaelManaged();
rijndaelCipher.Key = Convert.FromBase64String(Session_key); // Encoding.UTF8.GetBytes(AesKey);
rijndaelCipher.IV = Convert.FromBase64String(iv);// Encoding.UTF8.GetBytes(AesIV);
rijndaelCipher.Mode = CipherMode.CBC;
rijndaelCipher.Padding = PaddingMode.PKCS7;
ICryptoTransform transform = rijndaelCipher.CreateDecryptor();
byte[] plainText = transform.TransformFinalBlock(encryData, 0, encryData.Length);
string result = Encoding.Default.GetString(plainText);
if (!string.IsNullOrEmpty(result))
{
using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read))
{
using (StreamReader srDecrypt = new StreamReader(csDecrypt))
{
result = srDecrypt.ReadToEnd();
}
}
var jObj = JObject.Parse(result);
phoneNum = jObj.GetStringValue("phoneNumber");
}
return result;
return phoneNum;
}
}
}
\ No newline at end of file
......@@ -4,6 +4,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Security.Cryptography;
using System.Text;
namespace Edu.Common.Plugin
......@@ -101,7 +102,7 @@ namespace Edu.Common.Plugin
{
//请求路径
string url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + AppId + "&secret=" + AppSecret + "&js_code=" + Code + "&grant_type=authorization_code";
resultInfo = Common.Plugin.HttpHelper.HttpGet(url);
resultInfo = Common.Plugin.HttpHelper.HttpGet(url);
if (resultInfo != null && !string.IsNullOrEmpty(resultInfo))
{
userInfo = JsonConvert.DeserializeObject<result>(resultInfo);
......@@ -117,6 +118,39 @@ namespace Edu.Common.Plugin
return userInfo;
}
/// <summary>
/// 获取微信授权手机号码
/// </summary>
/// <param name="encryptedData"></param>
/// <param name="sessionKey"></param>
/// <param name="ivStr"></param>
/// <returns></returns>
public static string GetWechatMobile(string encryptedData, string sessionKey, string ivStr)
{
try
{
//16进制数据转换成byte
var encryptedDataByte = Convert.FromBase64String(encryptedData); // strToToHexByte(text);
var rijndaelCipher = new RijndaelManaged
{
Key = Convert.FromBase64String(sessionKey),
IV = Convert.FromBase64String(ivStr),
Mode = CipherMode.CBC,
Padding = PaddingMode.PKCS7
};
var transform = rijndaelCipher.CreateDecryptor();
var plainText = transform.TransformFinalBlock(encryptedDataByte, 0, encryptedDataByte.Length);
var result = Encoding.Default.GetString(plainText);
return result;
}
catch (Exception ex)
{
return null;
}
}
}
......@@ -154,8 +188,6 @@ namespace Edu.Common.Plugin
}
#region 实体类
/// <summary>
/// 微信小程序验证返回结果
/// </summary>
......@@ -185,10 +217,11 @@ namespace Edu.Common.Plugin
/// 错误提示信息
/// </summary>
public string errmsg { get; set; }
}
/// <summary>
/// 电话号码
/// </summary>
public string phoneNumber { get; set; }
}
#endregion
}
}
\ No newline at end of file
......@@ -240,19 +240,19 @@ namespace Edu.WebApi.Controllers.APP
}
else
{
if (!string.IsNullOrEmpty(model.UnionId))//UnionId是否为空,为空则绑定手机号与UnionId
{
if (UnionId != model.UnionId)
{
return ApiResult.Failed("手机号与绑定的微信账户不一致", new { Error = 0 });
}
}
else
{
model.UnionId = UnionId;
model.OpenId = OpenId;
var flag = accountModule.UpdateAccountUnionId(model);
}
//if (!string.IsNullOrEmpty(model.UnionId))//UnionId是否为空,为空则绑定手机号与UnionId
//{
// if (UnionId != model.UnionId)
// {
// return ApiResult.Failed("手机号与绑定的微信账户不一致", new { Error = 0 });
// }
//}
//else
//{
// model.UnionId = UnionId;
// model.OpenId = OpenId;
// var flag = accountModule.UpdateAccountUnionId(model);
//}
if (model.Status == Common.Enum.DateStateEnum.Delete)
{
return ApiResult.Failed(message: $"此账号【{ account }】已禁用", new { Error = 2 });
......@@ -338,33 +338,33 @@ namespace Edu.WebApi.Controllers.APP
string encryptedData = parms.GetStringValue("encryptedData");
string iv = parms.GetStringValue("iv");
string Appid = Common.Config.AppID;
var Secret = Common.Config.AppSecret;
string grant_type = "authorization_code";
//向微信服务端 使用登录凭证 code 获取 session_key 和 openid
string url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + Appid + "&secret=" + Secret + "&js_code=" + code + "&grant_type=" + grant_type;
string type = "utf-8";
GetUsersHelper GetUsersHelper = new GetUsersHelper();
JObject jo = null;
string _telPhone = "";
Common.Plugin.result res = new Common.Plugin.result();
try
{
string Appid = Common.Config.JiaXiaoHeAppId;
var Secret = Common.Config.JiaXiaoHeAppSecret;
string grant_type = "authorization_code";
//向微信服务端 使用登录凭证 code 获取 session_key 和 openid
string url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + Appid + "&secret=" + Secret + "&js_code=" + code + "&grant_type=" + grant_type;
string type = "utf-8";
GetUsersHelper GetUsersHelper = new GetUsersHelper();
JObject jo = null;
string _telPhone = "";
string j = GetUsersHelper.GetUrltoHtml(url, type);//获取微信服务器返回字符串
//将字符串转换为json格式
jo = (JObject)JsonConvert.DeserializeObject(j);
Common.Plugin.result res = new Common.Plugin.result
{
//微信服务器验证成功
openid = jo["openid"].ToString(),
session_key = jo["session_key"].ToString()
};
if (!string.IsNullOrWhiteSpace(jo["openid"].ToString()))
jo = JObject.Parse(j);
//微信服务器验证成功
res.openid = jo.GetStringValue("openid");
res.session_key = jo.GetStringValue("session_key");
if (!string.IsNullOrWhiteSpace(res.openid))
{
if (!String.IsNullOrEmpty(encryptedData) && !string.IsNullOrEmpty(iv))
{
//解析手机号码
_telPhone = Common.EncryptionHelper.AES_decrypt(encryptedData, jo["session_key"].ToString(), iv);
_telPhone = Common.EncryptionHelper.AES_decrypt(encryptedData, res.session_key, iv);
res.phoneNumber = _telPhone;
}
}
}
......@@ -373,7 +373,7 @@ namespace Edu.WebApi.Controllers.APP
Common.Plugin.LogHelper.Write(ex, string.Format("GetGuestWeiXinMobile:msg:{0},request:{1},URL:{2}", Common.Plugin.JsonHelper.Serialize(jo), RequestParm.Msg.ToString(), url));
return ApiResult.Failed("获取失败");
}
return ApiResult.Success("", _telPhone);
return ApiResult.Success("", res);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment