123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- using System;
- using System.Collections.Generic;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Linq;
- using Microsoft.Extensions.Hosting;
- using MySystem;
- using MySystem.Models;
- using LitJson;
- using Library;
- public class HaoDaExtHelper
- {
- public readonly static HaoDaExtHelper Instance = new HaoDaExtHelper();
- private HaoDaExtHelper()
- {
- }
-
- public void StartWeChat()
- {
- Thread th = new Thread(StartWeChatDo);
- th.IsBackground = true;
- th.Start();
- }
- private void StartWeChatDo()
- {
- while (true)
- {
- string content = RedisDbconn.Instance.RPop<string>("WeChatForHaoDaQueue");
- if (!string.IsNullOrEmpty(content))
- {
- WeChatAddInfo(int.Parse(content));
- }
- else
- {
- Thread.Sleep(10000);
- }
- }
- }
- public void WeChatAddInfo(int Id)
- {
- try
- {
- WebCMSEntities db = new WebCMSEntities();
- MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
- string result = WeChatFunctionForHD.Instance.MerchantApply(info);
- if (result.Contains("\"applyment_id\":"))
- {
- JsonData json = JsonMapper.ToObject(result);
- string applyment_id = json["applyment_id"].ToString();
- RedisDbconn.Instance.AddList("WeChatResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"ApplymentId\":\"" + applyment_id + "\"}");
- }
- else if (result.Contains("\"message\":"))
- {
- MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
- JsonData jsonObj = JsonMapper.ToObject(result);
- info.Status = -1;
- merchant.Status = -1;
- info.WeChatRemark = jsonObj["message"].ToString();
- db.SaveChanges();
- }
- db.Dispose();
- }
- catch(Exception ex)
- {
- LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "微信开户意愿申请异常");
- }
- }
- public void StartAlipay()
- {
- Thread th = new Thread(StartAlipayDo);
- th.IsBackground = true;
- th.Start();
- }
- private void StartAlipayDo()
- {
- while (true)
- {
- string content = RedisDbconn.Instance.RPop<string>("AlipayForHaoDaQueue");
- if (!string.IsNullOrEmpty(content))
- {
- AlipayAddInfo(int.Parse(content));
- }
- else
- {
- Thread.Sleep(10000);
- }
- }
- }
- public void AlipayAddInfo(int Id)
- {
- try
- {
- WebCMSEntities db = new WebCMSEntities();
- MerchantAddInfo info = db.MerchantAddInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantAddInfo();
- string result = AlipayFunctionForHD.Instance.AuthOrderCreate(info, info.AlipayAuthToken);
- JsonData jsonObj = JsonMapper.ToObject(result);
- if (jsonObj["alipay_merchant_indirect_authorder_create_response"]["code"].ToString() == "10000")
- {
- string order_no = jsonObj["alipay_merchant_indirect_authorder_create_response"]["order_no"].ToString();
- RedisDbconn.Instance.AddList("AlipayResultForHaoDaQueue", "{\"MerchantId\":\"" + Id + "\",\"order_no\":\"" + order_no + "\"}");
- }
- else
- {
- MerchantInfo merchant = db.MerchantInfo.FirstOrDefault(m => m.Id == Id) ?? new MerchantInfo();
- info.QueryCount = -1;
- merchant.QueryCount = -1;
- info.AlipayRemark = jsonObj["alipay_merchant_indirect_authorder_create_response"]["msg"].ToString();
- db.SaveChanges();
- }
- db.Dispose();
- }
- catch(Exception ex)
- {
- LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\n" + ex.ToString(), "支付宝开户意愿申请异常");
- }
- }
- }
|