HaoDaHelper.cs 58 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061
  1. using System.Net.Mime;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Security.Cryptography;
  6. using System.Text;
  7. using Library;
  8. using System.Net;
  9. using System.IO;
  10. using Aop.Api.Util;
  11. using LitJson;
  12. namespace MySystem
  13. {
  14. /// <summary>
  15. /// 好哒相关接口
  16. /// </summary>
  17. public class HaoDaHelper
  18. {
  19. public readonly static HaoDaHelper Instance = new HaoDaHelper();
  20. private HaoDaHelper()
  21. {
  22. }
  23. #region 盒易付
  24. //测试环境
  25. // string BoxRequestUrl = "https://openapi-test.iboxpay.com";
  26. // string BoxAppId = "AT7317781468267548672";
  27. // string BoxAppSecret = "OfWuHQdhQfnE8NaF4xdtgk4B9CYqnbri";
  28. // string BoxPublicKey = "";
  29. // string BrhCode = "001040";
  30. //生产环境
  31. // string BoxRequestUrl = "https://openapi.iboxpay.com";
  32. // string BoxAppId = "AP7175619323825451008";
  33. // string BoxAppSecret = "hUfR53gdjyfiZTBR5bILanMqRD1dXD7y";
  34. // string BoxPublicKey = "";
  35. // public static string BrhCode = "030145";
  36. // string BoxRequestUrl = "https://openapi.iboxpay.com";
  37. // string BoxAppId = "AP8322645764893728768";
  38. // string BoxAppSecret = "je1TElprp3jzWETsG3FcWqtmpreEHqZS";
  39. // string BoxPublicKey = "";
  40. // public static string BrhCode = "";
  41. /// <summary>
  42. /// 新创建商户
  43. /// </summary>
  44. /// <param name="request"></param>
  45. /// <returns></returns>
  46. public string AddNewMerchant(AddNewMerchant request, int BrandId = 0, string AgentTag = "1")
  47. {
  48. var BoxRequestUrl = HaodaUnionParam.BoxRequestUrl;
  49. if (BrandId == 1)
  50. {
  51. BoxRequestUrl = HaodaParam.BoxRequestUrl;
  52. string oprInvitedCode = "";
  53. if (BrandId == 1)
  54. {
  55. if(string.IsNullOrEmpty(RedisDbconn.Instance.Get<string>("AgentInvitedCode:" + AgentTag)))
  56. {
  57. oprInvitedCode = RedisDbconn.Instance.Get<string>("AgentInvitedCode:1");
  58. }
  59. else
  60. {
  61. oprInvitedCode = RedisDbconn.Instance.Get<string>("AgentInvitedCode:" + AgentTag);
  62. }
  63. }
  64. request.oprInvitedCode = oprInvitedCode;
  65. }
  66. // request.brh = BrhCode;
  67. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "好哒新创建商户");
  68. string req = Newtonsoft.Json.JsonConvert.SerializeObject(request);
  69. LogHelper.Instance.WriteLog(req, "好哒新创建商户");
  70. Dictionary<string, string> headdic = GetHeader(req, BrandId, AgentTag);
  71. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  72. LogHelper.Instance.WriteLog("请求头\n" + head, "好哒新创建商户");
  73. LogHelper.Instance.WriteLog("请求参数\n" + req, "好哒新创建商户");
  74. LogHelper.Instance.WriteLog("请求地址:" + BoxRequestUrl + "/api/inst/mcht/new_create_mcht", "好哒新创建商户");
  75. string result = PostWebRequest(BoxRequestUrl + "/api/inst/mcht/new_create_mcht", req, headdic);
  76. LogHelper.Instance.WriteLog("返回\n" + result + "\n\n", "好哒新创建商户");
  77. return result;
  78. }
  79. /// <summary>
  80. /// 查询商户审核状态
  81. /// </summary>
  82. /// <param name="instId">机构编号</param>
  83. /// <param name="mchtNo">收款商户号</param>
  84. /// <returns></returns>
  85. public string QueryMerchantStatus(string instId, string mchtNo, int BrandId = 0, string AgentTag = "1")
  86. {
  87. if(string.IsNullOrEmpty(mchtNo))
  88. {
  89. return "{}";
  90. }
  91. var BoxRequestUrl = HaodaUnionParam.BoxRequestUrl;
  92. if (BrandId == 1) BoxRequestUrl = HaodaParam.BoxRequestUrl;
  93. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "好哒查询商户审核状态");
  94. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  95. reqdic.Add("instId", instId);
  96. reqdic.Add("mchtNo", mchtNo);
  97. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  98. LogHelper.Instance.WriteLog(req, "好哒查询商户审核状态");
  99. Dictionary<string, string> headdic = GetHeader(req, BrandId, AgentTag);
  100. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  101. LogHelper.Instance.WriteLog("请求头\n" + head, "好哒查询商户审核状态");
  102. LogHelper.Instance.WriteLog("请求参数\n" + req, "好哒查询商户审核状态");
  103. LogHelper.Instance.WriteLog("请求地址:" + BoxRequestUrl + "/api/inst/mcht/query_mcht_audit", "好哒查询商户审核状态");
  104. string result = PostWebRequest(BoxRequestUrl + "/api/inst/mcht/query_mcht_audit", req, headdic);
  105. LogHelper.Instance.WriteLog("返回\n" + result + "\n\n", "好哒查询商户审核状态");
  106. return result;
  107. }
  108. /// <summary>
  109. /// 查询实名认证状态
  110. /// </summary>
  111. /// <param name="mchtNo">慧掌柜商户号</param>
  112. /// <param name="storeNo">慧掌柜门店号</param>
  113. /// <returns></returns>
  114. public string QueryAuthStatus(string mchtNo, string storeNo, int BrandId = 0, string AgentTag = "1")
  115. {
  116. var BoxRequestUrl = HaodaUnionParam.BoxRequestUrl;
  117. if (BrandId == 1) BoxRequestUrl = HaodaParam.BoxRequestUrl;
  118. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "好哒查询实名认证状态");
  119. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  120. reqdic.Add("mchtNo", mchtNo); // 慧掌柜商户号
  121. reqdic.Add("storeNo", storeNo); // 慧掌柜门店号
  122. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  123. LogHelper.Instance.WriteLog(req, "好哒查询实名认证状态");
  124. Dictionary<string, string> headdic = GetHeader(req, BrandId, AgentTag);
  125. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  126. LogHelper.Instance.WriteLog("请求头\n" + head, "好哒查询实名认证状态");
  127. LogHelper.Instance.WriteLog("请求参数\n" + req, "好哒查询实名认证状态");
  128. LogHelper.Instance.WriteLog("请求地址:" + BoxRequestUrl + "/api/hzg/v2/wechat/queryVerifiedResult.json", "好哒查询实名认证状态");
  129. string result = PostWebRequest(BoxRequestUrl + "/api/hzg/v2/wechat/queryVerifiedResult.json", req, headdic);
  130. LogHelper.Instance.WriteLog("返回\n" + result + "\n\n", "好哒查询实名认证状态");
  131. return result;
  132. }
  133. /// <summary>
  134. /// 查询实名认证二维码
  135. /// </summary>
  136. /// <param name="mchtNo">慧掌柜商户号</param>
  137. /// <param name="storeNo">慧掌柜门店号</param>
  138. /// <returns></returns>
  139. public string QueryAuthQRcode(string mchtNo, string storeNo, int BrandId = 0, string AgentTag = "1")
  140. {
  141. var BoxRequestUrl = HaodaUnionParam.BoxRequestUrl;
  142. if (BrandId == 1) BoxRequestUrl = HaodaParam.BoxRequestUrl;
  143. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "好哒查询实名认证二维码");
  144. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  145. reqdic.Add("mchtNo", mchtNo); // 慧掌柜商户号
  146. reqdic.Add("storeNo", storeNo); // 慧掌柜门店号
  147. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  148. LogHelper.Instance.WriteLog(req, "好哒查询实名认证二维码");
  149. Dictionary<string, string> headdic = GetHeader(req, BrandId, AgentTag);
  150. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  151. LogHelper.Instance.WriteLog("请求头\n" + head, "好哒查询实名认证二维码");
  152. LogHelper.Instance.WriteLog("请求参数\n" + req, "好哒查询实名认证二维码");
  153. LogHelper.Instance.WriteLog("请求地址:" + BoxRequestUrl + "/api/hzg/v2/wechat/queryVerifiedQrcode.json", "好哒查询实名认证二维码");
  154. string result = PostWebRequest(BoxRequestUrl + "/api/hzg/v2/wechat/queryVerifiedQrcode.json", req, headdic);
  155. LogHelper.Instance.WriteLog("返回\n" + result + "\n\n", "好哒查询实名认证二维码");
  156. return result;
  157. }
  158. /// <summary>
  159. /// 微信公众号和小程序支付接口
  160. /// </summary>
  161. /// <param name="mchtNo">盒子的商户编号</param>
  162. /// <param name="storeNo">盒子的门店编码</param>
  163. /// <param name="outOrderNo">商户订单号</param>
  164. /// <param name="transAmount">交易金额,单位:分</param>
  165. /// <param name="callbackUrl">交易完成之后,商户接收交易结果通知的地址</param>
  166. /// <param name="subOpenId">用户子标识</param>
  167. /// <param name="confirmCode">支付确认码</param>
  168. /// <param name="subAppId">公众号或者小程序appId</param>
  169. /// <param name="subAppIdType">对应的类型,默认为公众号, SUBSCRIPTION: 公众号 MINI_PROGRAM: 小程序</param>
  170. /// <param name="ledgerModel">分账类型:1不分账 2分账,注意只有开通了分账才能传这个字段</param>
  171. /// <returns></returns>
  172. public string WeChatPay(string mchtNo, string storeNo, string outOrderNo, string transAmount, string callbackUrl, string subOpenId, string confirmCode, string subAppId, string subAppIdType, string ledgerModel, int BrandId = 0, string AgentTag = "1")
  173. {
  174. var BoxRequestUrl = HaodaUnionParam.BoxRequestUrl;
  175. if (BrandId == 1) BoxRequestUrl = HaodaParam.BoxRequestUrl;
  176. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "好哒微信公众号和小程序支付");
  177. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  178. reqdic.Add("mchtNo", mchtNo); //盒子的商户编号
  179. reqdic.Add("storeNo", storeNo); //盒子的门店编码
  180. reqdic.Add("outOrderNo", outOrderNo); //商户订单号
  181. reqdic.Add("transAmount", transAmount); //交易金额,单位:分
  182. reqdic.Add("callbackUrl", callbackUrl); //交易完成之后,商户接收交易结果通知的地址
  183. reqdic.Add("subOpenId", subOpenId); //用户子标识
  184. reqdic.Add("confirmCode", confirmCode); //支付确认码,由4位纯数字组成,每次请求时随机生成
  185. reqdic.Add("subAppId", subAppId); //公众号或者小程序appId
  186. reqdic.Add("subAppIdType", subAppIdType); //subAppId 对应的类型,默认为公众号, SUBSCRIPTION: 公众号 MINI_PROGRAM: 小程序
  187. reqdic.Add("ledgerModel", ledgerModel); //分账类型:1不分账 2分账,注意只有开通了分账才能传这个字段
  188. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  189. LogHelper.Instance.WriteLog(req, "好哒微信公众号和小程序支付");
  190. Dictionary<string, string> headdic = GetHeader(req, BrandId, AgentTag);
  191. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  192. LogHelper.Instance.WriteLog("请求头\n" + head, "好哒微信公众号和小程序支付");
  193. LogHelper.Instance.WriteLog("请求参数\n" + req, "好哒微信公众号和小程序支付");
  194. LogHelper.Instance.WriteLog("请求地址:" + BoxRequestUrl + "/api/hzg/v2/unitedtrade/wechat_js_pay", "好哒微信公众号和小程序支付");
  195. string result = PostWebRequest(BoxRequestUrl + "/api/hzg/v2/unitedtrade/wechat_js_pay", req, headdic);
  196. LogHelper.Instance.WriteLog("返回\n" + result + "\n\n", "好哒微信公众号和小程序支付");
  197. return result;
  198. }
  199. /// <summary>
  200. /// 支付宝服务窗支付接口
  201. /// </summary>
  202. /// <param name="mchtNo">盒子的商户编号</param>
  203. /// <param name="storeNo">盒子的门店编码</param>
  204. /// <param name="outOrderNo">商户订单号</param>
  205. /// <param name="transAmount">交易金额,单位:分</param>
  206. /// <param name="callbackUrl">交易完成之后,商户接收交易结果通知的地址</param>
  207. /// <param name="subOpenId">支付宝用户标识</param>
  208. /// <param name="confirmCode">支付确认码,由4位纯数字组成,每次请求时随机生成</param>
  209. /// <returns></returns>
  210. public string Alipay(string mchtNo, string storeNo, string outOrderNo, string transAmount, string callbackUrl, string subOpenId, string confirmCode, int BrandId = 0, string AgentTag = "1")
  211. {
  212. var BoxRequestUrl = HaodaUnionParam.BoxRequestUrl;
  213. if (BrandId == 1) BoxRequestUrl = HaodaParam.BoxRequestUrl;
  214. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "好哒支付宝服务窗支付");
  215. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  216. reqdic.Add("mchtNo", mchtNo); //盒子的商户编号
  217. reqdic.Add("storeNo", storeNo); //盒子的门店编码
  218. reqdic.Add("outOrderNo", outOrderNo); //商户订单号
  219. reqdic.Add("transAmount", transAmount); //交易金额,单位:分
  220. reqdic.Add("callbackUrl", callbackUrl); //交易完成之后,商户接收交易结果通知的地址
  221. reqdic.Add("subOpenId", subOpenId); //支付宝用户标识
  222. reqdic.Add("confirmCode", confirmCode); //支付确认码,由4位纯数字组成,每次请求时随机生成
  223. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  224. LogHelper.Instance.WriteLog(req, "好哒支付宝服务窗支付");
  225. Dictionary<string, string> headdic = GetHeader(req, BrandId, AgentTag);
  226. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  227. LogHelper.Instance.WriteLog("请求头\n" + head, "好哒支付宝服务窗支付");
  228. LogHelper.Instance.WriteLog("请求参数\n" + req, "好哒支付宝服务窗支付");
  229. LogHelper.Instance.WriteLog("请求地址:" + BoxRequestUrl + "/api/hzg/v2/unitedtrade/wechat_js_pay", "好哒支付宝服务窗支付");
  230. string result = PostWebRequest(BoxRequestUrl + "/api/hzg/v2/unitedtrade/wechat_js_pay", req, headdic);
  231. LogHelper.Instance.WriteLog("返回\n" + result + "\n\n", "好哒支付宝服务窗支付");
  232. return result;
  233. }
  234. /// <summary>
  235. /// 聚合支付退款接口
  236. /// </summary>
  237. /// <param name="mchtNo">盒子的商户编号</param>
  238. /// <param name="storeNo">盒子的门店编号</param>
  239. /// <param name="outRefundNo">商户退款订单号</param>
  240. /// <param name="outOrderNo">商户支付订单号</param>
  241. /// <param name="refundAmount">退款金额,单位:分</param>
  242. /// <returns></returns>
  243. public string AggregatedPayRefund(string mchtNo, string storeNo, string outRefundNo, string outOrderNo, string refundAmount, int BrandId = 0, string AgentTag = "1")
  244. {
  245. var BoxRequestUrl = HaodaUnionParam.BoxRequestUrl;
  246. if (BrandId == 1) BoxRequestUrl = HaodaParam.BoxRequestUrl;
  247. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "好哒聚合支付退款");
  248. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  249. reqdic.Add("mchtNo", mchtNo); // 盒子的商户编号
  250. reqdic.Add("storeNo", storeNo); // 盒子的门店编号
  251. reqdic.Add("outRefundNo", outRefundNo); //32 商户退款订单号
  252. reqdic.Add("outOrderNo", outOrderNo); // 商户支付订单号
  253. reqdic.Add("refundAmount", refundAmount); //10 退款金额,单位:分
  254. reqdic.Add("refundReason", "门店消费补贴"); //退款原因
  255. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  256. LogHelper.Instance.WriteLog(req, "好哒聚合支付退款");
  257. Dictionary<string, string> headdic = GetHeader(req, BrandId, AgentTag);
  258. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  259. LogHelper.Instance.WriteLog("请求头\n" + head, "好哒聚合支付退款");
  260. LogHelper.Instance.WriteLog("请求参数\n" + req, "好哒聚合支付退款");
  261. LogHelper.Instance.WriteLog("请求地址:" + BoxRequestUrl + "/api/hzg/v2/unitedtrade/refund", "好哒聚合支付退款");
  262. string result = PostWebRequest(BoxRequestUrl + "/api/hzg/v2/unitedtrade/refund", req, headdic);
  263. LogHelper.Instance.WriteLog("返回\n" + result + "\n\n", "好哒聚合支付退款");
  264. return result;
  265. }
  266. /// <summary>
  267. /// 开通分账功能
  268. /// </summary>
  269. /// <param name="mchtNo">慧掌柜商户号(进件接口返回的outMchtNo字段)</param>
  270. /// <param name="storeNo">慧掌柜门店号</param>
  271. /// <returns></returns>
  272. public string OpenDivideAccounts(string mchtNo, string storeNo, int BrandId = 0, string AgentTag = "1")
  273. {
  274. var BoxRequestUrl = HaodaUnionParam.BoxRequestUrl;
  275. if (BrandId == 1) BoxRequestUrl = HaodaParam.BoxRequestUrl;
  276. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "好哒开通分账");
  277. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  278. reqdic.Add("mchtNo", mchtNo); // 慧掌柜商户号
  279. reqdic.Add("storeNo", storeNo); // 慧掌柜门店号
  280. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  281. LogHelper.Instance.WriteLog(req, "好哒开通分账");
  282. Dictionary<string, string> headdic = GetHeader(req, BrandId, AgentTag);
  283. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  284. LogHelper.Instance.WriteLog("请求头\n" + head, "好哒开通分账");
  285. LogHelper.Instance.WriteLog("请求参数\n" + req, "好哒开通分账");
  286. LogHelper.Instance.WriteLog("请求地址:" + BoxRequestUrl + "/api/v3/hzg/part/mcht/reg", "好哒开通分账");
  287. string result = PostWebRequest(BoxRequestUrl + "/api/v3/hzg/part/mcht/reg", req, headdic);
  288. LogHelper.Instance.WriteLog("返回\n" + result + "\n\n", "好哒开通分账");
  289. return result;
  290. }
  291. /// <summary>
  292. /// 分账接收方签约
  293. /// </summary>
  294. /// <param name="acctNo">账户号</param>
  295. /// <param name="mchtNo">慧掌柜商户号</param>
  296. /// <param name="storeNo">慧掌柜门店号</param>
  297. /// <returns></returns>
  298. public string DivideAccountsSign(string acctNo, string mchtNo, string storeNo, int BrandId = 0, string AgentTag = "1")
  299. {
  300. var BoxRequestUrl = HaodaUnionParam.BoxRequestUrl;
  301. if (BrandId == 1) BoxRequestUrl = HaodaParam.BoxRequestUrl;
  302. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "好哒分账接收方签约");
  303. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  304. reqdic.Add("acctNo", acctNo); // 账户号
  305. reqdic.Add("mchtNo", mchtNo); // 慧掌柜商户号
  306. reqdic.Add("storeNo", storeNo); // 慧掌柜门店号
  307. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  308. LogHelper.Instance.WriteLog(req, "好哒分账接收方签约");
  309. Dictionary<string, string> headdic = GetHeader(req, BrandId, AgentTag);
  310. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  311. LogHelper.Instance.WriteLog("请求头\n" + head, "好哒分账接收方签约");
  312. LogHelper.Instance.WriteLog("请求参数\n" + req, "好哒分账接收方签约");
  313. LogHelper.Instance.WriteLog("请求地址:" + BoxRequestUrl + "/api/v3/hzg/part/acct/bind_mcht", "好哒分账接收方签约");
  314. string result = PostWebRequest(BoxRequestUrl + "/api/v3/hzg/part/acct/bind_mcht", req, headdic);
  315. LogHelper.Instance.WriteLog("返回\n" + result + "\n\n", "好哒分账接收方签约");
  316. return result;
  317. }
  318. /// <summary>
  319. /// 添加分账接收方账户
  320. /// </summary>
  321. /// <param name="request"></param>
  322. /// <returns></returns>
  323. public string AddOpenDivideAccounts(AddOpenDivideAccounts request, int BrandId = 0, string AgentTag = "1")
  324. {
  325. var BoxRequestUrl = HaodaUnionParam.BoxRequestUrl;
  326. if (BrandId == 1) BoxRequestUrl = HaodaParam.BoxRequestUrl;
  327. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "好哒添加分账接收方账户");
  328. string req = Newtonsoft.Json.JsonConvert.SerializeObject(request);
  329. LogHelper.Instance.WriteLog(req, "好哒添加分账接收方账户");
  330. Dictionary<string, string> headdic = GetHeader(req, BrandId, AgentTag);
  331. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  332. LogHelper.Instance.WriteLog("请求头\n" + head, "好哒添加分账接收方账户");
  333. LogHelper.Instance.WriteLog("请求参数\n" + req, "好哒添加分账接收方账户");
  334. LogHelper.Instance.WriteLog("请求地址:" + BoxRequestUrl + "/api/v3/hzg/part/acct/register", "好哒添加分账接收方账户");
  335. string result = PostWebRequest(BoxRequestUrl + "/api/v3/hzg/part/acct/register", req, headdic);
  336. LogHelper.Instance.WriteLog("返回\n" + result + "\n\n", "好哒添加分账接收方账户");
  337. return result;
  338. }
  339. /// <summary>
  340. /// 分账交易详情查询
  341. /// </summary>
  342. /// <param name="mchtNo">慧掌柜商户号</param>
  343. /// <param name="orderNo">交易订单号 </param>
  344. /// <returns></returns>
  345. public string QueryOrderDivideAccounts(string mchtNo, string orderNo, int BrandId = 0, string AgentTag = "1")
  346. {
  347. var BoxRequestUrl = HaodaUnionParam.BoxRequestUrl;
  348. if (BrandId == 1) BoxRequestUrl = HaodaParam.BoxRequestUrl;
  349. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "好哒分账交易详情查询");
  350. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  351. reqdic.Add("mchtNo", mchtNo); // 慧掌柜商户号
  352. reqdic.Add("orderNo", orderNo); // 交易订单号
  353. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  354. LogHelper.Instance.WriteLog(req, "好哒分账交易详情查询");
  355. Dictionary<string, string> headdic = GetHeader(req, BrandId, AgentTag);
  356. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  357. LogHelper.Instance.WriteLog("请求头\n" + head, "好哒分账交易详情查询");
  358. LogHelper.Instance.WriteLog("请求参数\n" + req, "好哒分账交易详情查询");
  359. LogHelper.Instance.WriteLog("请求地址:" + BoxRequestUrl + "/api/v3/hzg/part/acct/bind_mcht", "好哒分账交易详情查询");
  360. string result = PostWebRequest(BoxRequestUrl + "/api/v3/hzg/part/acct/bind_mcht", req, headdic);
  361. LogHelper.Instance.WriteLog("返回\n" + result + "\n\n", "好哒分账交易详情查询");
  362. return result;
  363. }
  364. /// <summary>
  365. /// 分账交易详情查询
  366. /// </summary>
  367. /// <param name="mchtNo">慧掌柜商户号</param>
  368. /// <param name="orderNo">交易订单号 </param>
  369. /// <returns></returns>
  370. public string QueryOrderDivideDetail(string mchtNo, string orderNo, int BrandId = 0, string AgentTag = "1")
  371. {
  372. var BoxRequestUrl = HaodaUnionParam.BoxRequestUrl;
  373. if (BrandId == 1) BoxRequestUrl = HaodaParam.BoxRequestUrl;
  374. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "好哒分账交易详情查询");
  375. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  376. reqdic.Add("mchtNo", mchtNo); // 慧掌柜商户号
  377. reqdic.Add("orderNo", orderNo); // 交易订单号
  378. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  379. LogHelper.Instance.WriteLog(req, "好哒分账交易详情查询");
  380. Dictionary<string, string> headdic = GetHeader(req, BrandId, AgentTag);
  381. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  382. LogHelper.Instance.WriteLog("请求头\n" + head, "好哒分账交易详情查询");
  383. LogHelper.Instance.WriteLog("请求参数\n" + req, "好哒分账交易详情查询");
  384. LogHelper.Instance.WriteLog("请求地址:" + BoxRequestUrl + "/api/v3/hzg/part/trade/clear/get", "好哒分账交易详情查询");
  385. string result = PostWebRequest(BoxRequestUrl + "/api/v3/hzg/part/trade/clear/get", req, headdic);
  386. LogHelper.Instance.WriteLog("返回\n" + result + "\n\n", "好哒分账交易详情查询");
  387. return result;
  388. }
  389. /// <summary>
  390. /// 订单分账申请
  391. /// </summary>
  392. /// <param name="request"></param>
  393. /// <returns></returns>
  394. ///
  395. public string OrderDivideAccounts(OrderDivideAccounts request, int BrandId = 0, string AgentTag = "1")
  396. {
  397. var BoxRequestUrl = HaodaUnionParam.BoxRequestUrl;
  398. if (BrandId == 1) BoxRequestUrl = HaodaParam.BoxRequestUrl;
  399. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "好哒订单分账申请");
  400. string req = Newtonsoft.Json.JsonConvert.SerializeObject(request);
  401. LogHelper.Instance.WriteLog(req, "好哒订单分账申请");
  402. Dictionary<string, string> headdic = GetHeader(req, BrandId, AgentTag);
  403. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  404. LogHelper.Instance.WriteLog("请求头\n" + head, "好哒订单分账申请");
  405. LogHelper.Instance.WriteLog("请求参数\n" + req, "好哒订单分账申请");
  406. LogHelper.Instance.WriteLog("请求地址:" + BoxRequestUrl + "/api/v3/hzg/part/order/apply", "好哒订单分账申请");
  407. string result = PostWebRequest(BoxRequestUrl + "/api/v3/hzg/part/order/apply", req, headdic);
  408. LogHelper.Instance.WriteLog("返回\n" + result + "\n\n", "好哒订单分账申请");
  409. return result;
  410. }
  411. /// <summary>
  412. /// 订单分账结果查询
  413. /// </summary>
  414. /// <param name="applyNo">分账批次号</param>
  415. /// <param name="mchtNo">慧掌柜商户号</param>
  416. /// <returns></returns>
  417. public string OrderDivideAccountsQuery(string applyNo, string mchtNo, int BrandId = 0, string AgentTag = "1")
  418. {
  419. var BoxRequestUrl = HaodaUnionParam.BoxRequestUrl;
  420. if (BrandId == 1) BoxRequestUrl = HaodaParam.BoxRequestUrl;
  421. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "好哒订单分账结果查询");
  422. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  423. reqdic.Add("applyNo", applyNo); // 账户号
  424. reqdic.Add("mchtNo", mchtNo); // 慧掌柜商户号
  425. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  426. LogHelper.Instance.WriteLog(req, "好哒订单分账结果查询");
  427. Dictionary<string, string> headdic = GetHeader(req, BrandId, AgentTag);
  428. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  429. LogHelper.Instance.WriteLog("请求头\n" + head, "好哒订单分账结果查询");
  430. LogHelper.Instance.WriteLog("请求参数\n" + req, "好哒订单分账结果查询");
  431. LogHelper.Instance.WriteLog("请求地址:" + BoxRequestUrl + "/api/v3/hzg/part/apply/query", "好哒订单分账结果查询");
  432. string result = PostWebRequest(BoxRequestUrl + "/api/v3/hzg/part/apply/query", req, headdic);
  433. LogHelper.Instance.WriteLog("返回\n" + result + "\n\n", "好哒订单分账结果查询");
  434. return result;
  435. }
  436. /// <summary>
  437. /// 商户修改银行卡
  438. /// </summary>
  439. /// <param name="request"></param>
  440. /// <returns></returns>
  441. public string ChangeMerchantCard(ChangeMerchantCard request, int BrandId = 0, string AgentTag = "1")
  442. {
  443. var BoxRequestUrl = HaodaUnionParam.BoxRequestUrl;
  444. if (BrandId == 1) BoxRequestUrl = HaodaParam.BoxRequestUrl;
  445. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "好哒商户修改银行卡");
  446. string req = Newtonsoft.Json.JsonConvert.SerializeObject(request);
  447. LogHelper.Instance.WriteLog(req, "好哒商户修改银行卡");
  448. Dictionary<string, string> headdic = GetHeader(req, BrandId, AgentTag);
  449. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  450. LogHelper.Instance.WriteLog("请求头\n" + head, "好哒商户修改银行卡");
  451. LogHelper.Instance.WriteLog("请求参数\n" + req, "好哒商户修改银行卡");
  452. LogHelper.Instance.WriteLog("请求地址:" + BoxRequestUrl + "/api/inst/mcht/update_acct", "好哒商户修改银行卡");
  453. string result = PostWebRequest(BoxRequestUrl + "/api/inst/mcht/update_acct", req, headdic);
  454. LogHelper.Instance.WriteLog("返回\n" + result + "\n\n", "好哒商户修改银行卡");
  455. return result;
  456. }
  457. /// <summary>
  458. /// 查询修改银行卡任务审核状态
  459. /// </summary>
  460. /// <param name="mchtNo">收款商户号</param>
  461. /// <param name="taskId">任务id</param>
  462. /// <returns></returns>
  463. public string QueryChangeCardStatus(string mchtNo, string taskId, int BrandId = 0, string AgentTag = "1")
  464. {
  465. var BoxRequestUrl = HaodaUnionParam.BoxRequestUrl;
  466. if (BrandId == 1) BoxRequestUrl = HaodaParam.BoxRequestUrl;
  467. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "好哒查询修改银行卡任务审核状态");
  468. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  469. reqdic.Add("mchtNo", mchtNo);
  470. reqdic.Add("taskId", taskId);
  471. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  472. LogHelper.Instance.WriteLog(req, "好哒查询修改银行卡任务审核状态");
  473. Dictionary<string, string> headdic = GetHeader(req, BrandId, AgentTag);
  474. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  475. LogHelper.Instance.WriteLog("请求头\n" + head, "好哒查询修改银行卡任务审核状态");
  476. LogHelper.Instance.WriteLog("请求参数\n" + req, "好哒查询修改银行卡任务审核状态");
  477. LogHelper.Instance.WriteLog("请求地址:" + BoxRequestUrl + "/api/inst/mcht/query_acct_task", "好哒查询修改银行卡任务审核状态");
  478. string result = PostWebRequest(BoxRequestUrl + "/api/inst/mcht/query_acct_task", req, headdic);
  479. LogHelper.Instance.WriteLog("返回\n" + result + "\n\n", "好哒查询修改银行卡任务审核状态");
  480. return result;
  481. }
  482. /// <summary>
  483. /// 绑定微信appid接口
  484. /// </summary>
  485. /// <param name="mchtNo">盒子的商户编号</param>
  486. /// <param name="storeNo">盒子的门店编号</param>
  487. /// <param name="subAppId">公众号appid或者小程序appid</param>
  488. /// <returns></returns>
  489. public string BindWeChatAppId(string mchtNo, string storeNo, string subAppId, int BrandId = 0, string AgentTag = "1")
  490. {
  491. var BoxRequestUrl = HaodaUnionParam.BoxRequestUrl;
  492. if (BrandId == 1) BoxRequestUrl = HaodaParam.BoxRequestUrl;
  493. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "好哒绑定微信appid接口");
  494. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  495. reqdic.Add("mchtNo", mchtNo); // 盒子商户号
  496. reqdic.Add("storeNo", storeNo); // 盒子门店号
  497. reqdic.Add("subAppId", subAppId); // 公众号appid或者小程序appid
  498. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  499. LogHelper.Instance.WriteLog(req, "好哒绑定微信appid接口");
  500. Dictionary<string, string> headdic = GetHeader(req, BrandId, AgentTag);
  501. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  502. LogHelper.Instance.WriteLog("请求头\n" + head, "好哒绑定微信appid接口");
  503. LogHelper.Instance.WriteLog("请求参数\n" + req, "好哒绑定微信appid接口");
  504. LogHelper.Instance.WriteLog("请求地址:" + BoxRequestUrl + "/api/hzg/v2/wechat/add_sub_config", "好哒绑定微信appid接口");
  505. string result = PostWebRequest(BoxRequestUrl + "/api/hzg/v2/wechat/add_sub_config", req, headdic);
  506. LogHelper.Instance.WriteLog("返回\n" + result + "\n\n", "好哒绑定微信appid接口");
  507. return result;
  508. }
  509. /// <summary>
  510. /// 到账记录查询
  511. /// </summary>
  512. /// <param name="mchtNo">商户号</param>
  513. /// <param name="startTime">查询开始时间(yyyy-MM-dd)</param>
  514. /// <param name="endTime">查询结束时间(yyyy-MM-dd),最大查询时间区间31天</param>
  515. /// <param name="tradeMchtNo">收单商户号(15位)</param>
  516. /// <param name="cardNo">结算卡号</param>
  517. /// <param name="settleStatus">出款状态(0:入账成功、1:入账失败、2:结算超时、3:入账受理成功、4:已提交结算请求)</param>
  518. /// <param name="page">当前页数,默认1</param>
  519. /// <param name="rows">每页大小,默认10,最大500</param>
  520. /// <returns></returns>
  521. public string QueryAccountList(string mchtNo, string startTime, string endTime, string tradeMchtNo, string cardNo, string settleStatus, string page = "1", string rows = "10", int BrandId = 0, string AgentTag = "1")
  522. {
  523. var BoxRequestUrl = HaodaUnionParam.BoxRequestUrl;
  524. if (BrandId == 1) BoxRequestUrl = HaodaParam.BoxRequestUrl;
  525. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "好哒到账记录查询");
  526. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  527. reqdic.Add("mchtNo", mchtNo); // 盒子商户号
  528. reqdic.Add("startTime", startTime); // 查询开始时间(yyyy-MM-dd)
  529. reqdic.Add("endTime", endTime); // 查询结束时间(yyyy-MM-dd),最大查询时间区间31天
  530. reqdic.Add("tradeMchtNo", tradeMchtNo); // 收单商户号(15位)
  531. reqdic.Add("cardNo", cardNo); // 结算卡号
  532. reqdic.Add("settleStatus", settleStatus); // 出款状态(0:入账成功、1:入账失败、2:结算超时、3:入账受理成功、4:已提交结算请求)
  533. reqdic.Add("page", page); // 当前页数,默认1
  534. reqdic.Add("rows", rows); // 每页大小,默认10,最大500
  535. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  536. LogHelper.Instance.WriteLog(req, "好哒到账记录查询");
  537. Dictionary<string, string> headdic = GetHeader(req, BrandId, AgentTag);
  538. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  539. LogHelper.Instance.WriteLog("请求头\n" + head, "好哒到账记录查询");
  540. LogHelper.Instance.WriteLog("请求参数\n" + req, "好哒到账记录查询");
  541. LogHelper.Instance.WriteLog("请求地址:" + BoxRequestUrl + "/api/v3/hzg/accb/to_account/query", "好哒到账记录查询");
  542. string result = PostWebRequest(BoxRequestUrl + "/api/v3/hzg/accb/to_account/query", req, headdic);
  543. LogHelper.Instance.WriteLog("返回\n" + result + "\n\n", "好哒到账记录查询");
  544. return result;
  545. }
  546. /// <summary>
  547. /// 到账记录详情
  548. /// </summary>
  549. /// <param name="mchtNo">商户号</param>
  550. /// <param name="id"></param>
  551. /// <returns></returns>
  552. public string QueryAccountDetail(string mchtNo, string id, int BrandId = 0, string AgentTag = "1")
  553. {
  554. var BoxRequestUrl = HaodaUnionParam.BoxRequestUrl;
  555. if (BrandId == 1) BoxRequestUrl = HaodaParam.BoxRequestUrl;
  556. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "好哒到账记录详情");
  557. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  558. reqdic.Add("mchtNo", mchtNo); // 商户号
  559. reqdic.Add("id", id); // id
  560. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  561. LogHelper.Instance.WriteLog(req, "好哒到账记录详情");
  562. Dictionary<string, string> headdic = GetHeader(req, BrandId, AgentTag);
  563. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  564. LogHelper.Instance.WriteLog("请求头\n" + head, "好哒到账记录详情");
  565. LogHelper.Instance.WriteLog("请求参数\n" + req, "好哒到账记录详情");
  566. LogHelper.Instance.WriteLog("请求地址:" + BoxRequestUrl + "/api/v3/hzg/accb/to_account/get", "好哒到账记录详情");
  567. string result = PostWebRequest(BoxRequestUrl + "/api/v3/hzg/accb/to_account/get", req, headdic);
  568. LogHelper.Instance.WriteLog("返回\n" + result + "\n\n", "好哒到账记录详情");
  569. return result;
  570. }
  571. /// <summary>
  572. /// 聚合支付查询接口
  573. /// </summary>
  574. /// <param name="mchtNo">商户号</param>
  575. /// <param name="outOrderNo">商户订单号</param>
  576. /// <returns></returns>
  577. public string QueryTradeDetail(string mchtNo, string outOrderNo, int BrandId = 0, string AgentTag = "1")
  578. {
  579. var BoxRequestUrl = HaodaUnionParam.BoxRequestUrl;
  580. if (BrandId == 1) BoxRequestUrl = HaodaParam.BoxRequestUrl;
  581. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "好哒聚合支付查询");
  582. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  583. reqdic.Add("mchtNo", mchtNo); // 商户号
  584. reqdic.Add("outOrderNo", outOrderNo); // 商户订单号
  585. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  586. LogHelper.Instance.WriteLog(req, "好哒聚合支付查询");
  587. Dictionary<string, string> headdic = GetHeader(req, BrandId, AgentTag);
  588. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  589. LogHelper.Instance.WriteLog("请求头\n" + head, "好哒聚合支付查询");
  590. LogHelper.Instance.WriteLog("请求参数\n" + req, "好哒聚合支付查询");
  591. LogHelper.Instance.WriteLog("请求地址:" + BoxRequestUrl + "/api/hzg/v2/unitedtrade/query_status", "好哒聚合支付查询");
  592. string result = PostWebRequest(BoxRequestUrl + "/api/hzg/v2/unitedtrade/query_status", req, headdic);
  593. LogHelper.Instance.WriteLog("返回\n" + result + "\n\n", "好哒聚合支付查询");
  594. return result;
  595. }
  596. /// <summary>
  597. /// 聚合支付退款查询接口
  598. /// </summary>
  599. /// <param name="mchtNo">商户号</param>
  600. /// <param name="storeNo">门店编号</param>
  601. /// <param name="outRefundNo">退款订单号</param>
  602. /// <returns></returns>
  603. public string QueryRefundDetail(string mchtNo, string storeNo, string outRefundNo, int BrandId = 0, string AgentTag = "1")
  604. {
  605. var BoxRequestUrl = HaodaUnionParam.BoxRequestUrl;
  606. if (BrandId == 1) BoxRequestUrl = HaodaParam.BoxRequestUrl;
  607. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "好哒退款查询");
  608. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  609. reqdic.Add("mchtNo", mchtNo); // 商户号
  610. reqdic.Add("storeNo", storeNo); // 商户订单号
  611. reqdic.Add("outRefundNo", outRefundNo);
  612. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  613. LogHelper.Instance.WriteLog(req, "好哒退款查询");
  614. Dictionary<string, string> headdic = GetHeader(req, BrandId, AgentTag);
  615. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  616. LogHelper.Instance.WriteLog("请求头\n" + head, "好哒退款查询");
  617. LogHelper.Instance.WriteLog("请求参数\n" + req, "好哒退款查询");
  618. LogHelper.Instance.WriteLog("请求地址:" + BoxRequestUrl + "/api/hzg/v2/unitedtrade/refund_query", "好哒退款查询");
  619. string result = PostWebRequest(BoxRequestUrl + "/api/hzg/v2/unitedtrade/refund_query", req, headdic);
  620. LogHelper.Instance.WriteLog("返回\n" + result + "\n\n", "好哒退款查询");
  621. return result;
  622. }
  623. /// <summary>
  624. /// 修改商户费率
  625. /// </summary>
  626. /// <param name="request"></param>
  627. /// <returns></returns>
  628. public string SetFee(string mchtNo, string feeRate, int BrandId = 0, string AgentTag = "1")
  629. {
  630. var BoxRequestUrl = HaodaUnionParam.BoxRequestUrl;
  631. if (BrandId == 1) BoxRequestUrl = HaodaParam.BoxRequestUrl;
  632. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "好哒商户修改费率");
  633. Dictionary<string, object> request = new Dictionary<string, object>();
  634. request.Add("mchtNo", mchtNo); // 商户号
  635. request.Add("alipayRate", feeRate);
  636. request.Add("wechatPayRate", feeRate);
  637. request.Add("unionPayRate", feeRate);
  638. string req = Newtonsoft.Json.JsonConvert.SerializeObject(request);
  639. LogHelper.Instance.WriteLog(req, "好哒商户修改费率");
  640. Dictionary<string, string> headdic = GetHeader(req, BrandId, AgentTag);
  641. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  642. LogHelper.Instance.WriteLog("请求头\n" + head, "好哒商户修改费率");
  643. LogHelper.Instance.WriteLog("请求参数\n" + req, "好哒商户修改费率");
  644. LogHelper.Instance.WriteLog("请求地址:" + BoxRequestUrl + "/api/inst/mcht/update_disc", "好哒商户修改费率");
  645. string result = PostWebRequest(BoxRequestUrl + "/api/inst/mcht/update_disc", req, headdic);
  646. LogHelper.Instance.WriteLog("返回\n" + result + "\n\n", "好哒商户修改费率");
  647. return result;
  648. }
  649. public Dictionary<string, string> GetHeader(string req, int BrandId = 0, string Agent = "1")
  650. {
  651. var BoxAppId = HaodaUnionParam.BoxAppId;
  652. var BoxAppSecret = HaodaUnionParam.BoxAppSecret;
  653. if (BrandId == 1)
  654. {
  655. if(string.IsNullOrEmpty(RedisDbconn.Instance.Get<string>("AgentAppId:" + Agent)))
  656. {
  657. BoxAppId = RedisDbconn.Instance.Get<string>("AgentAppId:1");
  658. BoxAppSecret = RedisDbconn.Instance.Get<string>("AgentAppSecret:1");
  659. }
  660. else
  661. {
  662. BoxAppId = RedisDbconn.Instance.Get<string>("AgentAppId:" + Agent);
  663. BoxAppSecret = RedisDbconn.Instance.Get<string>("AgentAppSecret:" + Agent);
  664. }
  665. }
  666. Dictionary<string, string> headdic = new Dictionary<string, string>();
  667. string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
  668. // headdic.Add("appid", BoxAppId);//开发者id
  669. // headdic.Add("appsecret", BoxAppSecret);//开发者密码
  670. headdic.Add("X-Up-AppId", BoxAppId);
  671. headdic.Add("X-Timestamp", timestamp);
  672. headdic.Add("X-Sign-Type", "SHA-256");
  673. headdic.Add("X-Sign", SHA256Sign(timestamp + BoxAppSecret + req));
  674. return headdic;
  675. }
  676. public string SHA256Sign(string toSignStr)
  677. {
  678. byte[] toSignByte = Encoding.UTF8.GetBytes(toSignStr);
  679. SHA256 sha256 = SHA256.Create();
  680. byte[] signByte = sha256.ComputeHash(toSignByte);
  681. string sign = Convert.ToBase64String(signByte);
  682. return sign;
  683. }
  684. public bool VerifySign(string toSignStr, string signStr, int BrandId = 0, string AgentTag = "1")
  685. {
  686. var BoxPublicKey = HaodaUnionParam.BoxPublicKey;
  687. if (BrandId == 1) BoxPublicKey = HaodaParam.BoxPublicKey;
  688. byte[] toSignByte = Encoding.Default.GetBytes(toSignStr);
  689. byte[] signByte = Convert.FromBase64String(signStr);
  690. var toKey = Convert.FromBase64String(BoxPublicKey);
  691. var rsaroot = RSA.Create();
  692. rsaroot.ImportSubjectPublicKeyInfo(toKey, out _);
  693. var publicKeyParameters = rsaroot.ExportParameters(false);
  694. using (var rsa = RSA.Create())
  695. {
  696. rsa.ImportParameters(publicKeyParameters);
  697. var sha256 = SHA256.Create();
  698. var hash = sha256.ComputeHash(toSignByte);
  699. return rsa.VerifyHash(hash, signByte, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  700. }
  701. }
  702. public string SignData(string toSignStr, int BrandId = 0, string AgentTag = "1")
  703. {
  704. var BoxPublicKey = HaodaUnionParam.BoxPublicKey;
  705. if (BrandId == 1) BoxPublicKey = HaodaParam.BoxPublicKey;
  706. byte[] toSignByte = Encoding.UTF8.GetBytes(toSignStr);
  707. var toKey = Convert.FromBase64String(BoxPublicKey);
  708. var rsaroot = RSA.Create();
  709. rsaroot.ImportSubjectPublicKeyInfo(toKey, out _);
  710. var publicKeyParameters = rsaroot.ExportParameters(false);
  711. using (var rsa = RSA.Create())
  712. {
  713. rsa.ImportParameters(publicKeyParameters);
  714. var sha256 = SHA256.Create();
  715. var hash = sha256.ComputeHash(toSignByte);
  716. byte[] endByte = rsa.SignData(toSignByte, HashAlgorithmName.SHA256, RSASignaturePadding.Pkcs1);
  717. return Convert.ToBase64String(endByte);
  718. }
  719. }
  720. private string PostWebRequest(string postUrl, string paramData, Dictionary<string, string> headers)
  721. {
  722. string ret = string.Empty;
  723. try
  724. {
  725. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "请求好哒API日志");
  726. LogHelper.Instance.WriteLog(postUrl, "请求好哒API日志");
  727. LogHelper.Instance.WriteLog(paramData, "请求好哒API日志");
  728. byte[] postData = System.Text.Encoding.UTF8.GetBytes(paramData);
  729. // 设置提交的相关参数
  730. System.Net.HttpWebRequest request = System.Net.WebRequest.Create(postUrl) as System.Net.HttpWebRequest;
  731. System.Text.Encoding myEncoding = System.Text.Encoding.UTF8;
  732. request.Method = "POST";
  733. request.KeepAlive = false;
  734. request.AllowAutoRedirect = true;
  735. request.ContentType = "application/json";
  736. foreach (string key in headers.Keys)
  737. {
  738. request.Headers.Add(key, headers[key]);
  739. }
  740. request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";
  741. request.ContentLength = postData.Length;
  742. // 提交请求数据
  743. System.IO.Stream outputStream = request.GetRequestStream();
  744. outputStream.Write(postData, 0, postData.Length);
  745. outputStream.Close();
  746. System.Net.HttpWebResponse response;
  747. System.IO.Stream responseStream;
  748. System.IO.StreamReader reader;
  749. string srcString;
  750. response = request.GetResponse() as System.Net.HttpWebResponse;
  751. responseStream = response.GetResponseStream();
  752. reader = new System.IO.StreamReader(responseStream, System.Text.Encoding.UTF8);
  753. srcString = reader.ReadToEnd();
  754. ret = srcString; //返回值赋值
  755. reader.Close();
  756. LogHelper.Instance.WriteLog(srcString, "请求好哒API日志");
  757. }
  758. catch (System.Net.WebException ex)
  759. {
  760. System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)ex.Response;
  761. System.IO.Stream myResponseStream = response.GetResponseStream();
  762. //获取响应内容
  763. System.IO.StreamReader myStreamReader = new System.IO.StreamReader(myResponseStream);
  764. ret = myStreamReader.ReadToEnd();
  765. myResponseStream.Close();
  766. }
  767. catch (Exception ex)
  768. {
  769. ret = "fail";
  770. LogHelper.Instance.WriteLog(DateTime.Now.ToString() + "\r\n" + ex.ToString(), "请求好哒API异常");
  771. }
  772. return ret;
  773. }
  774. /// <summary>
  775. /// 获取文件令牌接口
  776. /// </summary>
  777. /// <param name="fileName">文件名</param>
  778. /// <param name="action">操作类型 0 上传图片</param>
  779. /// <returns></returns>
  780. public string GetToken(string fileName, string action, int BrandId = 0, string AgentTag = "1")
  781. {
  782. var BoxRequestUrl = HaodaUnionParam.BoxRequestUrl;
  783. if (BrandId == 1) BoxRequestUrl = HaodaParam.BoxRequestUrl;
  784. LogHelper.Instance.WriteLog(DateTime.Now.ToString(), "好哒获取文件令牌接口");
  785. Dictionary<string, object> reqdic = new Dictionary<string, object>();
  786. reqdic.Add("fileName", fileName); // 文件名
  787. reqdic.Add("action", action); // 操作类型 0 上传图片
  788. string req = Newtonsoft.Json.JsonConvert.SerializeObject(reqdic);
  789. LogHelper.Instance.WriteLog(req, "好哒获取文件令牌接口");
  790. Dictionary<string, string> headdic = GetHeader(req, BrandId, AgentTag);
  791. string head = Newtonsoft.Json.JsonConvert.SerializeObject(headdic);
  792. LogHelper.Instance.WriteLog("请求头\n" + head, "好哒获取文件令牌接口");
  793. LogHelper.Instance.WriteLog("请求参数\n" + req, "好哒获取文件令牌接口");
  794. LogHelper.Instance.WriteLog("请求地址:" + BoxRequestUrl + "/api/auth/v1/get_file_token", "好哒获取文件令牌接口");
  795. string result = PostWebRequest(BoxRequestUrl + "/api/auth/v1/get_file_token", req, headdic);
  796. LogHelper.Instance.WriteLog("返回\n" + result + "\n\n", "好哒获取文件令牌接口");
  797. return result;
  798. }
  799. /// <summary>
  800. /// 执行带文件上传的HTTP POST请求。
  801. /// </summary>
  802. /// <param name="url">请求地址</param>
  803. /// <param name="textParams">请求文本参数</param>
  804. /// <param name="fileParams">请求文件参数</param>
  805. /// <param name="charset">编码字符集</param>
  806. /// <returns>HTTP响应</returns>
  807. public string DoPost(string url, string token, IDictionary<string, string> textParams, IDictionary<string, FileItem> fileParams, string charset = "utf-8")
  808. {
  809. // 如果没有文件参数,则走普通POST请求
  810. if (fileParams == null || fileParams.Count == 0)
  811. {
  812. return "";
  813. }
  814. string boundary = DateTime.Now.Ticks.ToString("X"); // 随机分隔线
  815. HttpWebRequest req = GetWebRequest(url, "POST");
  816. req.Headers.Add("X-File-Token", token);
  817. req.ContentType = "multipart/form-data;charset=" + charset + ";boundary=" + boundary;
  818. Stream reqStream = req.GetRequestStream();
  819. byte[] itemBoundaryBytes = Encoding.GetEncoding(charset).GetBytes("\r\n--" + boundary + "\r\n");
  820. byte[] endBoundaryBytes = Encoding.GetEncoding(charset).GetBytes("\r\n--" + boundary + "--\r\n");
  821. // 组装文本请求参数
  822. string textTemplate = "Content-Disposition:form-data;name=\"{0}\"\r\nContent-Type:text/plain\r\n\r\n{1}";
  823. IEnumerator<KeyValuePair<string, string>> textEnum = textParams.GetEnumerator();
  824. while (textEnum.MoveNext())
  825. {
  826. string textEntry = string.Format(textTemplate, textEnum.Current.Key, textEnum.Current.Value);
  827. byte[] itemBytes = Encoding.GetEncoding(charset).GetBytes(textEntry);
  828. reqStream.Write(itemBoundaryBytes, 0, itemBoundaryBytes.Length);
  829. reqStream.Write(itemBytes, 0, itemBytes.Length);
  830. }
  831. // 组装文件请求参数
  832. string fileTemplate = "Content-Disposition:form-data;name=\"{0}\";filename=\"{1}\"\r\nContent-Type:{2}\r\n\r\n";
  833. IEnumerator<KeyValuePair<string, FileItem>> fileEnum = fileParams.GetEnumerator();
  834. while (fileEnum.MoveNext())
  835. {
  836. string key = fileEnum.Current.Key;
  837. FileItem fileItem = fileEnum.Current.Value;
  838. string fileEntry = string.Format(fileTemplate, key, fileItem.GetFileName(), fileItem.GetMimeType());
  839. byte[] itemBytes = Encoding.GetEncoding(charset).GetBytes(fileEntry);
  840. reqStream.Write(itemBoundaryBytes, 0, itemBoundaryBytes.Length);
  841. reqStream.Write(itemBytes, 0, itemBytes.Length);
  842. byte[] fileBytes = fileItem.GetContent();
  843. reqStream.Write(fileBytes, 0, fileBytes.Length);
  844. }
  845. reqStream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length);
  846. reqStream.Close();
  847. HttpWebResponse rsp = (HttpWebResponse)req.GetResponse();
  848. Encoding encoding = Encoding.GetEncoding(rsp.CharacterSet);
  849. return GetResponseAsString(rsp, encoding);
  850. }
  851. public HttpWebRequest GetWebRequest(string url, string method)
  852. {
  853. HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
  854. req.ServicePoint.Expect100Continue = false;
  855. req.Method = method;
  856. req.KeepAlive = true;
  857. req.Timeout = 100000;
  858. return req;
  859. }
  860. /// <summary>
  861. /// 把响应流转换为文本。
  862. /// </summary>
  863. /// <param name="rsp">响应流对象</param>
  864. /// <param name="encoding">编码方式</param>
  865. /// <returns>响应文本</returns>
  866. public string GetResponseAsString(HttpWebResponse rsp, Encoding encoding)
  867. {
  868. StringBuilder result = new StringBuilder();
  869. Stream stream = null;
  870. StreamReader reader = null;
  871. try
  872. {
  873. // 以字符流的方式读取HTTP响应
  874. stream = rsp.GetResponseStream();
  875. reader = new StreamReader(stream, encoding);
  876. // 按字符读取并写入字符串缓冲
  877. int ch = -1;
  878. while ((ch = reader.Read()) > -1)
  879. {
  880. // 过滤结束符
  881. char c = (char)ch;
  882. if (c != '\0')
  883. {
  884. result.Append(c);
  885. }
  886. }
  887. }
  888. finally
  889. {
  890. // 释放资源
  891. if (reader != null) reader.Close();
  892. if (stream != null) stream.Close();
  893. if (rsp != null) rsp.Close();
  894. }
  895. return result.ToString();
  896. }
  897. /// <summary>
  898. /// 获取好哒开放平台文件名
  899. /// </summary>
  900. /// <param name="token">上传图片凭证token</param>
  901. /// <param name="value">图片路径</param>
  902. /// <returns></returns>
  903. public string ReturnFileName(string token, string value, int BrandId = 0, string AgentTag = "1")
  904. {
  905. var BoxRequestUrl = HaodaUnionParam.BoxRequestUrl;
  906. if (BrandId == 1) BoxRequestUrl = HaodaParam.BoxRequestUrl;
  907. Dictionary<string, string> file = new Dictionary<string, string>();
  908. file.Add("fileName", value.Substring(value.LastIndexOf("/")).Trim('/'));
  909. if (string.IsNullOrEmpty(value.Split(',')[0]))
  910. {
  911. return "";
  912. }
  913. FileItem item = PublicFunction.GetNetFileItem(AppConfig.Base.OssHost + value.Split(',')[0]);
  914. // FileItem item = new FileItem(function.getPath(value.Split(',')[0]));
  915. Dictionary<string, FileItem> files = new Dictionary<string, FileItem>();
  916. files.Add("file", item);
  917. var upLoadInfo = JsonMapper.ToObject(HaoDaHelper.Instance.DoPost(BoxRequestUrl + "/api/file/v1/upload_file", token, file, files, "utf-8"));
  918. if (upLoadInfo["code"].ToString() == "1")
  919. {
  920. return upLoadInfo["data"]["fileName"].ToString();
  921. }
  922. else
  923. {
  924. return "false";
  925. }
  926. }
  927. #endregion
  928. }
  929. }