diff --git a/Host/Controllers/UserController.cs b/Host/Controllers/UserController.cs index 4c403ce..b7ecb3f 100644 --- a/Host/Controllers/UserController.cs +++ b/Host/Controllers/UserController.cs @@ -570,33 +570,47 @@ namespace Home.Controllers [HttpPost, AllowAnonymous] public async Task TaoBao() { - Func> process = async (data) => + Func> process = async (data) => { var notifyOrder = data.FromJsonTo(); LogHelper.Info("TaoBao process"); if (notifyOrder == null || notifyOrder.Tid.NotHas()) - return false; + return ""; if (m_ScoreService.ExistTaoBaoScore(notifyOrder.Tid)) - return true; + return ""; // var phone = notifyOrder.ReceiverMobile.NotHas() ? notifyOrder.ReceiverPhone : notifyOrder.ReceiverMobile; // if (phone.NotHas()) return false; var userEntity = await m_UserService.Query(m => m.TaoBao == notifyOrder.BuyerNick).FirstOrDefaultAsync(); var phone = notifyOrder.BuyerNick; + string pas_result = ""; + Random rd = new Random(Guid.NewGuid().GetHashCode()); + for (int i = 0; i < 6; i++) + { + int rnd = rd.Next(0, 9); + pas_result += rnd.ToString(); + } + + Console.WriteLine("=================================================================="); + + string msg = ""; + if (userEntity == null) { userEntity = new User() { CreateType = UserCreateType.TaoBaoRegist, LoginCode = phone, - Password = "1234", + Password = pas_result, Phone = phone, TaoBao= notifyOrder.BuyerNick, id_code="" }; var ret = await m_UserService.Regist(userEntity); - if (ret.Code != ResultCode.C_SUCCESS) return false; + msg = "您好,打开网址:juip.com,登录会员名:"+phone+"("+notifyOrder.Payment+"元已充值到此账户),密码:"+pas_result+"。登录后点击网站上方的-产品购买,即可完成开通或续费。淘宝付款将随机赠送优惠券,欢迎您多来淘宝下单"; + if (ret.Code != ResultCode.C_SUCCESS) return msg; + } else { phone = userEntity.Phone; @@ -604,6 +618,8 @@ namespace Home.Controllers userEntity.TaoBao= notifyOrder.BuyerNick; await m_UserService.Update(userEntity); } + msg = "您好,"+notifyOrder.Payment+"元已充值到充值到您的会员中,会员号为:"+userEntity.LoginCode+",打开网址:juip.com,登录后点击网站上方的-产品购买,即可完成开通或续费。淘宝付款将随机赠送优惠券,欢迎您多来淘宝下单"; + } var amountInfo = new UpdateAmountRequest() @@ -624,7 +640,15 @@ namespace Home.Controllers await m_TaoBaoService.Add(taobaoEntity); - return retAmount.Code == ResultCode.C_SUCCESS; + + // await Task.Delay(3000); + // Console.WriteLine("==================================================================="); + // var send_msg_info = await m_TaoBaoService.SengMsg(notifyOrder.Tid,msg); + // Console.WriteLine("==================================================================="); + // Console.WriteLine(send_msg_info); + // Console.WriteLine("==================================================================="); + + return msg; }; Func> refunds = async (data) => { @@ -649,7 +673,7 @@ namespace Home.Controllers var info = ""; if (aopic == 2){ info = await m_TaoBaoService.ReceivedMsg(this.Request, process); - } else if(aopic == 256){ + } else if(aopic == 256){//退款 var his_order= m_TaoBaoRefundService.Query(m => m.Tid == refundInfos.Tid).FirstOrDefault(); if (his_order == null){ info = await m_TaoBaoRefundService.ReceivedRefundMsg(this.Request, refunds); diff --git a/Services/Hncore.Pass.Sells/Service/SellerTaoBaoService.cs b/Services/Hncore.Pass.Sells/Service/SellerTaoBaoService.cs index d2b9058..d3dd6e1 100644 --- a/Services/Hncore.Pass.Sells/Service/SellerTaoBaoService.cs +++ b/Services/Hncore.Pass.Sells/Service/SellerTaoBaoService.cs @@ -7,6 +7,10 @@ using System.Threading.Tasks; using Hncore.Infrastructure.Serializer; using System; using System.Security.Cryptography; +using System.Net; +using System.Web; +using System.IO; +using System.Text; namespace Hncore.Pass.Sells.Service { @@ -30,7 +34,7 @@ namespace Hncore.Pass.Sells.Service return entity; } - public async Task ReceivedMsg(HttpRequest request, Func> process) + public async Task ReceivedMsg(HttpRequest request, Func> process) { string appSecret = "xrzmtmfv46mmt9c9rzt2g7c74h9g7u7u"; long timestamp = long.Parse(request.Query["timestamp"]); @@ -61,7 +65,8 @@ namespace Hncore.Pass.Sells.Service */ if (process != null) { - if (await process(json)) + var msg_info = await process(json); + if (msg_info != "") { var returnJson = new { @@ -69,9 +74,9 @@ namespace Hncore.Pass.Sells.Service DoMemoUpdate = new { Flag = 1, - Memo = "购买成功" + Memo = msg_info }, - AliwwMsg = "购买成功" + AliwwMsg = msg_info }; return returnJson.ToJson(); } @@ -79,6 +84,71 @@ namespace Hncore.Pass.Sells.Service return ""; } + public async Task SengMsg(string Tid,string msg) + { + string appSecret = "xrzmtmfv46mmt9c9rzt2g7c74h9g7u7u"; + + + //阿奇所发送消息 + string accessToken = "TbAldsa2ph4sa7de69r5vvccm2767evg7k9rs4gsf4273upm8c"; + + WebRequest apiRequest = WebRequest.Create("http://gw.api.agiso.com/alds/WwMsg/Send"); + apiRequest.Method = "POST"; + apiRequest.ContentType = "application/x-www-form-urlencoded"; + apiRequest.Headers.Add("Authorization", "Bearer " + accessToken); + apiRequest.Headers.Add("ApiVersion", "1"); + + TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); + var args = new Dictionary() + { + {"timestamp",Convert.ToInt64(ts.TotalSeconds).ToString()}, + {"tid",Tid}, + {"msg",msg}, + }; + args.Add("sign", Sign(args, appSecret)); + + string postData = ""; + foreach (var p in args) + { + if (!String.IsNullOrEmpty(postData)) + { + postData += "&"; + } + string tmpStr = String.Format("{0}={1}", p.Key, HttpUtility.UrlEncode(p.Value)); + postData += tmpStr; + } + + using (var sw = new StreamWriter(apiRequest.GetRequestStream())) + { + sw.Write(postData); + } + WebResponse apiResponse = null; + try + { + apiResponse = apiRequest.GetResponse(); + } + catch (WebException we) + { + if (we.Status == WebExceptionStatus.ProtocolError) + { + apiResponse = (we.Response as HttpWebResponse); + } + else{ + //TODO:处理异常 + return ""; + } + } + using(Stream apiDataStream = apiResponse.GetResponseStream()){ + using(StreamReader apiReader = new StreamReader(apiDataStream, Encoding.UTF8)){ + string apiResult = apiReader.ReadToEnd(); + apiReader.Close(); + apiResponse.Close(); + return apiResult; + } + } + + } + public async Task ReceivedRefundMsg(HttpRequest request, Func> process) { string appSecret = "xrzmtmfv46mmt9c9rzt2g7c74h9g7u7u";