123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Data;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Http;
- using Microsoft.Extensions.Logging;
- using Microsoft.Extensions.Options;
- using Microsoft.AspNetCore.Authorization;
- using MySystem.MainModels;
- using LitJson;
- using Library;
- using System.Security.Cryptography;
- using System.Text;
- namespace MySystem.Areas.Api.Controllers.v1
- {
- [Area("Api")]
- [Route("/v1/QrCodePlateMain/[controller]/[action]")]
- public class ConsumersController : BaseController
- {
- public ConsumersController(IHttpContextAccessor accessor, ILogger<BaseController> logger, IOptions<Setting> setting) : base(accessor, logger, setting)
- {
- }
- #region 首页-首页-个人信息-返现金额
-
- public JsonResult AmountInfo(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- Dictionary<string, object> Obj = AmountInfoDo(value);
- return Json(new AppResultJson() { Status = "1", Info = "", Data = Obj });
- }
- private Dictionary<string, object> AmountInfoDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- string OpenId = data["OpenId"].ToString();
- int Kind = int.Parse(data["Kind"].ToString());
- if (Kind == 1)
- {
- OpenId = AlipayMiniOpenIdDo(OpenId);
- }
- if (Kind == 2)
- {
- OpenId = WeChatMiniOpenIdDo(OpenId);
- }
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- var HeadPhoto = "";
- var NickName = "";
- var TotalAmount = 0.00M;
- var Amount = 0.00M;
- var Amount2 = 0.00M;
- var consumer = Services.Main.ConsumersService.Query(" and WechatOpenId=" + OpenId + "");
- var consumer2 = Services.Main2.ConsumersService.Query(" and WechatOpenId=" + OpenId + "");
- Amount = Services.Main.ConsumerProfitService.Sum(" and ConsumerId=" + consumer.Id + "", "GetMoney");
- Amount2 = Services.Main.ConsumerProfitService.Sum(" and ConsumerId=" + consumer.Id + "", "GetMoney");
- TotalAmount = Amount + Amount2;
- if (consumer.Id > 0)
- {
- HeadPhoto = consumer.HeadPhoto;
- NickName = consumer.NickName;
- }
- if (consumer2.Id > 0)
- {
- HeadPhoto = consumer2.HeadPhoto;
- NickName = consumer2.NickName;
- }
- Obj.Add("Amount", TotalAmount);
- Obj.Add("HeadPhoto", HeadPhoto);
- Obj.Add("NickName", NickName);
- return Obj;
- }
- #endregion
- #region 首页-首页-个人信息-修改个人信息
-
- public JsonResult EditPersonalInfo(string value)
- {
- value = DesDecrypt(value);
- JsonData data = JsonMapper.ToObject(value);
- AppResultJson result = EditPersonalInfoDo(value);
- return Json(new AppResultJson() { Status = result.Status, Info = result.Info, Data = result.Data });
- }
- private AppResultJson EditPersonalInfoDo(string value)
- {
- JsonData data = JsonMapper.ToObject(value);
- string OpenId = data["OpenId"].ToString();
- int Kind = int.Parse(data["Kind"].ToString());
- string HeadPhoto = data["HeadPhoto"].ToString();
- string NickName = data["NickName"].ToString();
- if (Kind == 1)
- {
- OpenId = AlipayMiniOpenIdDo(OpenId);
- }
- if (Kind == 2)
- {
- OpenId = WeChatMiniOpenIdDo(OpenId);
- }
- Dictionary<string, object> Obj = new Dictionary<string, object>();
- var consumer = maindb.Consumers.FirstOrDefault(m => m.WechatOpenId == OpenId) ?? new Consumers();
- var consumer2 = maindb2.Consumers.FirstOrDefault(m => m.WechatOpenId == OpenId) ?? new MainModels2.Consumers();
-
-
- if (string.IsNullOrEmpty(OpenId))
- {
- return new AppResultJson() { Status = "-1", Info = "微信或支付宝Id为空" };
- }
- if (consumer.Id > 0)
- {
- if (!string.IsNullOrEmpty(HeadPhoto))
- {
- consumer.HeadPhoto = HeadPhoto;
- }
- if (!string.IsNullOrEmpty(NickName))
- {
- consumer.NickName = NickName;
- }
- }
- if (consumer2.Id > 0)
- {
- if (!string.IsNullOrEmpty(HeadPhoto))
- {
- consumer2.HeadPhoto = HeadPhoto;
- }
- if (!string.IsNullOrEmpty(NickName))
- {
- consumer2.NickName = NickName;
- }
- }
- maindb.SaveChanges();
- maindb2.SaveChanges();
- return new AppResultJson() { Status = "1", Info = "", Data = Obj };
- }
- #endregion
- #region 消费者-微信小程序通过code获取openid
- public string WeChatMiniOpenIdDo(string code)
- {
- string url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + new WeChatFunction().AppId + "&secret=" + new WeChatFunction().AppSecret + "&js_code=" + code + "&grant_type=authorization_code";
- function.WriteLog(url, "微信小程序通过code获取openid");
- string result = function.GetWebRequest(url);
- function.WriteLog(result + "\n", "微信小程序通过code获取openid");
- JsonData jsonObj = JsonMapper.ToObject(result);
- string openid = jsonObj["openid"].ToString();
- return openid;
- }
- public Dictionary<string, string> getPhoneNumber(string encryptedData, string iv, string session_key)
- {
- Dictionary<string, string> Obj = new Dictionary<string, string>();
- try
- {
- byte[] encryData = Convert.FromBase64String(encryptedData);
- RijndaelManaged rijndaelCipher = new RijndaelManaged();
- rijndaelCipher.Key = Convert.FromBase64String(session_key);
- rijndaelCipher.IV = Convert.FromBase64String(iv);
- 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);
- dynamic model = Newtonsoft.Json.Linq.JToken.Parse(result) as dynamic;
- string phoneNumber = model.phoneNumber;
-
- if (string.IsNullOrEmpty(phoneNumber))
- {
- phoneNumber = "";
- }
- Obj.Add("Mobile", phoneNumber);
- }
- catch (Exception ex)
- {
- Obj.Add("Mobile", "err");
- function.WriteLog(DateTime.Now.ToString(), "微信小程序获取手机号异常");
- function.WriteLog(encryptedData, "微信小程序获取手机号异常");
- function.WriteLog(iv, "微信小程序获取手机号异常");
- function.WriteLog(session_key, "微信小程序获取手机号异常");
- function.WriteLog(ex.ToString(), "微信小程序获取手机号异常");
- function.WriteLog("\r\n\r\n", "微信小程序获取手机号异常");
- }
- return Obj;
- }
- public string filterEmoji(string str)
- {
- string origin = str;
- try
- {
-
- foreach (var a in str)
- {
- byte[] bts = System.Text.Encoding.UTF32.GetBytes(a.ToString());
- if (bts[0].ToString() == "253" && bts[1].ToString() == "255")
- {
- str = str.Replace(a.ToString(), "");
- }
- }
- }
- catch
- {
- str = origin;
- }
- return str;
- }
- #endregion
- #region 消费者-支付宝通过code获取openid
- public string AlipayMiniOpenIdDo(string code)
- {
- string openid = new AlipayFunction(_accessor.HttpContext).GetAlipayUserId(code);
- return openid;
- }
- #endregion
- }
- }
|