MicroMessageProcessing.cs 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. namespace LYFZ.WeixinServers.WeiXinAPP
  6. {
  7. public class MicroMessageProcessing
  8. {
  9. public MicroMessageProcessing()
  10. {
  11. }
  12. /// <summary>
  13. /// 微信输入信息内容绑定
  14. /// </summary>
  15. /// <param name="functionCode"></param>
  16. /// <param name="openId"></param>
  17. /// <param name="apiUrl"></param>
  18. /// <param name="cid"></param>
  19. /// <param name="appid"></param>
  20. /// <returns></returns>
  21. public static string WeiXinMessageData(string functionCode, string openId, string apiUrl,int cid,string appid)
  22. {
  23. string retMsg = "";
  24. try
  25. {
  26. switch (functionCode)
  27. {
  28. case "KeywordQuery":
  29. retMsg = KeywordQuery(openId, apiUrl, cid, appid);
  30. break;
  31. case "AccountBinding":
  32. retMsg = CheckAccountBinding(openId, apiUrl, cid, appid);
  33. break;
  34. case "UserBinding":
  35. retMsg = CheckUserBinding(openId, apiUrl, cid, appid);
  36. break;
  37. case "AccountUnbind":
  38. retMsg = CustomerAccountUnbind(openId, apiUrl, cid, appid);
  39. break;
  40. case "UnUserBinding":
  41. retMsg = UnUserBinding(openId, apiUrl, cid, appid);
  42. break;
  43. case "OrderQuery":
  44. retMsg = CustomerOrderQuery(openId, apiUrl, cid, appid);
  45. break;
  46. case "MemberQuery":
  47. retMsg = CustomerMemberQuery(openId, apiUrl, cid, appid);
  48. break;
  49. case "FinancialBriefing":
  50. retMsg = SearchFinanceToday(openId, apiUrl, cid, appid);
  51. break;
  52. case "CustomerRating":
  53. retMsg = CustomerRating(openId,apiUrl, cid, appid);
  54. break;
  55. }
  56. }
  57. catch (Exception ex)
  58. {
  59. LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + apiUrl + "” 错误消息:" + ex.Message, appid, Global.LogsDongleDomainList);
  60. }
  61. if (String.IsNullOrEmpty(retMsg))
  62. {
  63. retMsg = "";
  64. }
  65. return retMsg;
  66. }
  67. /// <summary>
  68. /// 客户评价
  69. /// </summary>
  70. /// <param name="openId"></param>
  71. /// <param name="apiUrl"></param>
  72. /// <param name="cid"></param>
  73. /// <param name="appid"></param>
  74. /// <returns></returns>
  75. private static string CustomerRating(string openId, string apiUrl, int cid, string appid)
  76. {
  77. string msg = "";
  78. string APIUrlString = apiUrl + "/api/WXApi.ashx/GetCustomerOrderPushMsg?openid=" + openId + "&cusid=" + cid + "&appid=" + appid;
  79. msg = LYFZ.WinAPI.HttpClientHelper.GetResponse(APIUrlString);
  80. dynamic dyObjcet= Newtonsoft.Json.JsonConvert.DeserializeObject(msg);
  81. return dyObjcet.data;
  82. }
  83. public static string WeiXinMessageFastData(string functionCode,string msgData, string openId, string apiUrl, int cid, string appid)
  84. {
  85. string retMsg = "";
  86. try
  87. {
  88. switch (functionCode)
  89. {
  90. case "AccountBinding":
  91. retMsg = AccountBinding(openId, apiUrl, cid, appid, msgData);
  92. break;
  93. case "UserBinding":
  94. retMsg = UserBinding(openId, apiUrl, cid, appid, msgData);
  95. break;
  96. case "AccountUnbind":
  97. retMsg = AccountUnbind(openId, apiUrl, cid, appid, msgData);
  98. break;
  99. case "UnUserBinding":
  100. retMsg = UnUserBindingExE(openId, apiUrl, cid, appid, msgData);
  101. break;
  102. }
  103. }
  104. catch (Exception ex)
  105. {
  106. LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + apiUrl + "” 错误消息:" + ex.Message, appid, Global.LogsDongleDomainList);
  107. }
  108. if (String.IsNullOrEmpty(retMsg))
  109. {
  110. retMsg = "";
  111. }
  112. return retMsg;
  113. }
  114. private static string UnUserBindingExE(string openId, string apiUrl, int cid, string appid, string msgData)
  115. {
  116. string[] msgDataList = msgData.Split('#');
  117. string APIUrlString = apiUrl + "/api/WXApi.ashx/UnBindWXCustomerAccount?openid=" + openId + "&type=" + "user" + "&mobile=" + msgDataList[1] + "&appid=" + appid;
  118. string getText = LYFZ.WinAPI.HttpClientHelper.GetResponse(APIUrlString);
  119. LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + APIUrlString + "” 接口返回信息:" + getText, appid, Global.LogsDongleDomainList);
  120. Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(getText);
  121. string code = jobject.GetValue("code").ToString();
  122. string content = "";
  123. if (code.Equals("200"))
  124. {
  125. content = "解除绑定成功!";
  126. }
  127. else
  128. {
  129. content = "绑定失败,失败信息:" + jobject.GetValue("data").ToString();
  130. }
  131. return content;
  132. }
  133. private static string AccountUnbind(string openId, string apiUrl, int cid, string appid, string msgData)
  134. {
  135. string[] msgDataList = msgData.Split('#');
  136. string APIUrlString = apiUrl + "/api/WXApi.ashx/UnBindWXCustomerAccount?openid=" + openId + "&type=" + "customer" + "&mobile=" + msgDataList[1] + "&appid=" + appid;
  137. string getText = LYFZ.WinAPI.HttpClientHelper.GetResponse(APIUrlString);
  138. LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + APIUrlString + "” 接口返回信息:" + getText, appid, Global.LogsDongleDomainList);
  139. Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(getText);
  140. string code = jobject.GetValue("code").ToString();
  141. string content = "";
  142. if (code.Equals("200"))
  143. {
  144. content = "解除绑定成功!";
  145. }
  146. else
  147. {
  148. content = "绑定失败,失败信息:" + jobject.GetValue("data").ToString();
  149. }
  150. return content;
  151. }
  152. private static string UserBinding(string openId, string apiUrl, int cid, string appid, string msgData)
  153. {
  154. string[] msgDataList = msgData.Split('#');
  155. string APIUrlString = apiUrl + "/api/WXApi.ashx/BindErpAccount?openid=" + openId + "&account=" + msgDataList[1] + "&password=" + msgDataList[2] + "&appid=" + appid;
  156. string getText = LYFZ.WinAPI.HttpClientHelper.GetResponse(APIUrlString);
  157. LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + APIUrlString + "” 接口返回信息:" + getText, appid, Global.LogsDongleDomainList);
  158. Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(getText);
  159. string code = jobject.GetValue("code").ToString();
  160. string content = "";
  161. if (code.Equals("200"))
  162. {
  163. content = "绑定成功!";
  164. }
  165. else
  166. {
  167. content = "绑定失败,失败信息:" + jobject.GetValue("data").ToString();
  168. }
  169. return content;
  170. }
  171. private static string AccountBinding(string openId, string apiUrl, int cid, string appid, string msgData)
  172. {
  173. string[] msgDataList = msgData.Split('#');
  174. string APIUrlString = apiUrl + "/api/WXApi.ashx/BindWXCustomerAccount?openid=" + openId + "&telePhone=" + msgDataList[1] + "&orderFourNumber=" + msgDataList[2] + "&appid=" + appid;
  175. string getText = LYFZ.WinAPI.HttpClientHelper.GetResponse(APIUrlString);
  176. LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + APIUrlString + "” 接口返回信息:" + getText, appid, Global.LogsDongleDomainList);
  177. Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(getText);
  178. string code = jobject.GetValue("code").ToString();
  179. string content = "";
  180. if (code.Equals("200"))
  181. {
  182. content = "绑定成功!";
  183. }
  184. else
  185. {
  186. content = "绑定失败,失败信息:" + jobject.GetValue("data").ToString();
  187. }
  188. return content;
  189. }
  190. /// <summary>
  191. /// 员工帐号绑定
  192. /// </summary>
  193. /// <param name="openId"></param>
  194. /// <param name="apiUrl"></param>
  195. /// <param name="cid"></param>
  196. /// <param name="appid"></param>
  197. /// <returns></returns>
  198. public static string GetUserBinding(string openId, string apiUrl, int cid, string appid)
  199. {
  200. // retHref = "客户帐号绑定回复:CFZHBD#手机号#订单号后4位\n手机号和订单号<a href=\"" + bindurl + "/WeiXinAPP/BondingAccount.aspx&openid=" + openId + "&dbType=cus\">点击这里,立即绑定</a>\n\n"
  201. //+"工作帐号绑定回复:YGZHBD#系统登录帐号#登录密码\n工作帐号<a href=\"" + bindurl + "/WeiXinAPP/UserBondingAccount.aspx&openid=" + openId + "&dbType=user\">点击这里,立即绑定</a>\n\n";
  202. return "工作帐号绑定回复:YGZHBD#系统登录帐号#登录密码\n工作帐号<a href=\"http://wx.lyfz.net/WeiXinAPP/BondingUser.aspx?openid=" + openId + "&cusid=" + cid.ToString() + "&appid=" + appid + "\">点击这里,立即绑定</a>";
  203. }
  204. /// <summary>
  205. ///
  206. /// </summary>
  207. /// <param name="openId"></param>
  208. /// <param name="apiUrl"></param>
  209. /// <param name="cid"></param>
  210. /// <param name="appid"></param>
  211. /// <returns></returns>
  212. public static string GetAccountBinding(string openId, string apiUrl, int cid, string appid)
  213. {
  214. return "客户帐号绑定回复:CFZHBD#手机号#订单号后4位\n手机号和订单号<a href=\"http://wx.lyfz.net/WeiXinAPP/BondingAccount.aspx?openid=" + openId + "&cusid=" + cid.ToString() + "&appid=" + appid + "\">点击这里,立即绑定</a>";
  215. }
  216. public static string GetErrorMsg(string errormsg,string openId, string apiUrl, int cid, string appid)
  217. {
  218. if (errormsg.Contains("未绑定"))
  219. {
  220. return errormsg + "\n" + GetUserBinding(openId,apiUrl, cid, appid)+"\n"
  221. + GetAccountBinding(openId, apiUrl, cid, appid);
  222. }
  223. else {
  224. return errormsg;
  225. }
  226. }
  227. public static string KeywordQuery(string openId, string apiUrl, int cid, string appid)
  228. {
  229. /*string cusRetInfo = " 订单查询:DDCX\n"
  230. + "会员查询:HYCX\n";
  231. endRetInfo = "客户帐号绑定回复:CFZHBD#手机号#订单号后4位\n";*/
  232. string retInfo = "发送以下代码查询相关业务:\n\n"
  233. + "订单查询:DDCX\n"
  234. + "会员查询:HYCX\n"
  235. + "客户帐号绑定回复:CFZHBD#手机号#订单号后4位\n"
  236. + "工作帐号绑定回复:YGZHBD#系统登录帐号#登录密码\n"
  237. + "今日财务查询:JRCWCX\n"
  238. + "解除绑定帐号:JCBDZH#手机号\n"
  239. + GetUserBinding(openId, apiUrl, cid, appid) + "\n"
  240. + GetAccountBinding(openId, apiUrl, cid, appid);
  241. return retInfo;
  242. }
  243. /// <summary>
  244. /// 员工帐号绑定
  245. /// </summary>
  246. /// <param name="openId"></param>
  247. /// <param name="apiUrl"></param>
  248. /// <param name="cid"></param>
  249. /// <param name="appid"></param>
  250. /// <returns></returns>
  251. public static string CheckUserBinding(string openId, string apiUrl, int cid, string appid)
  252. {
  253. string APIUrlString = apiUrl + "/api/WXApi.ashx/CheckWXUserAccount?openid=" + openId + "&appid=" + appid;
  254. string getText = LYFZ.WinAPI.HttpClientHelper.GetResponse(APIUrlString);
  255. LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + APIUrlString + "” 接口返回信息:" + getText, appid, Global.LogsDongleDomainList);
  256. Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(getText);
  257. string code = jobject.GetValue("code").ToString();
  258. string content = "";
  259. if (code.Equals("200"))
  260. {
  261. content = "账号已绑定,无需重复绑定!";
  262. }
  263. else
  264. {
  265. content = GetUserBinding(openId, apiUrl, cid, appid);
  266. }
  267. return content;
  268. }
  269. /// <summary>
  270. /// 财务数据
  271. /// </summary>
  272. /// <param name="openId"></param>
  273. /// <param name="cusModel"></param>
  274. /// <param name="context"></param>
  275. public static string SearchFinanceToday(string openId, string apiUrl,int cid, string appid)
  276. {
  277. string APIUrlString = apiUrl + "/api/WXApi.ashx/SearchFinanceToday?openid=" + openId + "&appid=" + appid;
  278. string getText = LYFZ.WinAPI.HttpClientHelper.GetResponse(APIUrlString);
  279. LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + APIUrlString + "” 接口返回信息:" + getText, appid, Global.LogsDongleDomainList);
  280. Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(getText);
  281. string code = jobject.GetValue("code").ToString();
  282. string content = "";
  283. if (code.Equals("200"))
  284. {
  285. content = jobject.GetValue("data").ToString();
  286. }
  287. else
  288. {
  289. content = GetErrorMsg(jobject.GetValue("data").ToString(),openId, apiUrl, cid, appid);
  290. //"账号绑定解除失败,失败原因:" + jobject.GetValue("data").ToString() + "";
  291. }
  292. return content;
  293. }
  294. public static string CustomerMemberQuery(string openId, string apiUrl, int cid, string appid)
  295. {
  296. string APIUrlString = apiUrl + "/api/WXApi.ashx/SearchCustomerData?openid=" + openId + "&appid=" + appid;
  297. string getText = LYFZ.WinAPI.HttpClientHelper.GetResponse(APIUrlString);
  298. LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + APIUrlString + "” 接口返回信息:" + getText, appid, Global.LogsDongleDomainList);
  299. Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(getText);
  300. string code = jobject.GetValue("code").ToString();
  301. string content = "";
  302. if (code.Equals("200"))
  303. {
  304. Newtonsoft.Json.Linq.JArray array = (Newtonsoft.Json.Linq.JArray)jobject.GetValue("data");
  305. ///发送模板数据
  306. if (array.Count > 0)
  307. {
  308. Newtonsoft.Json.Linq.JObject cusObject = (Newtonsoft.Json.Linq.JObject)array[0];
  309. content += "姓名:" + cusObject.GetValue("持卡人") + "\n";
  310. content += "电话:" + cusObject.GetValue("电话") + "\n";
  311. content += "性别:" + (cusObject.GetValue("性别").ToString() == "0" ? "男" : "女") + "\n";
  312. content += "会员卡号:" + (string.IsNullOrEmpty((string)cusObject.GetValue("会员卡号")) ? "未办理" : (string)cusObject.GetValue("会员卡号")) + "\n";
  313. content += "积分:" + cusObject.GetValue("积分") + "\n";
  314. content += "欠款:" + cusObject.GetValue("欠款") + "\n";
  315. content += "金额:" + cusObject.GetValue("金额") + "\n";
  316. content += "折扣:" + cusObject.GetValue("折扣") + "\n";
  317. }
  318. else
  319. {
  320. content = "当前客户没有数据";
  321. }
  322. }
  323. else
  324. {
  325. content = GetErrorMsg(jobject.GetValue("data").ToString(), openId, apiUrl, cid, appid);
  326. }
  327. return content;
  328. }
  329. public static string CustomerOrderQuery(string openId, string apiUrl, int cid, string appid)
  330. {
  331. string APIUrlString = apiUrl + "/api/WXApi.ashx/SearchCustomerOrder?openid=" + openId + "&appid=" + appid;
  332. string getText = LYFZ.WinAPI.HttpClientHelper.GetResponse(APIUrlString);
  333. LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + APIUrlString + "” 接口返回信息:" + getText, appid, Global.LogsDongleDomainList);
  334. Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(getText);
  335. string code = jobject.GetValue("code").ToString();
  336. string content = "";
  337. if (code.Equals("200"))
  338. {
  339. content = jobject.GetValue("data").ToString();
  340. ///发送模板数据
  341. }
  342. else
  343. {
  344. content = GetErrorMsg(jobject.GetValue("data").ToString(), openId, apiUrl, cid, appid);
  345. }
  346. return content;
  347. }
  348. /// <summary>
  349. /// 客户会员绑定
  350. /// </summary>
  351. /// <param name="openId"></param>
  352. /// <param name="apiUrl"></param>
  353. /// <param name="cid"></param>
  354. /// <param name="appid"></param>
  355. /// <returns></returns>
  356. public static string CheckAccountBinding(string openId, string apiUrl, int cid, string appid)
  357. {
  358. string APIUrlString = apiUrl + "/api/WXApi.ashx/CheckWXCustomerAccount?openid=" + openId + "&appid=" + appid;
  359. string getText = LYFZ.WinAPI.HttpClientHelper.GetResponse(APIUrlString);
  360. LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + APIUrlString + "” 接口返回信息:" + getText, appid, Global.LogsDongleDomainList);
  361. Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(getText);
  362. string code = jobject.GetValue("code").ToString();
  363. string content = "";
  364. if (code.Equals("200"))
  365. {
  366. content = "账号已绑定,无需重复绑定!";
  367. }
  368. else
  369. {
  370. content = GetAccountBinding(openId, apiUrl, cid, appid);
  371. }
  372. return content;
  373. }
  374. public static string CustomerAccountUnbind(string openId, string apiUrl, int cid, string appid)
  375. {
  376. string APIUrlString = apiUrl + "/api/WXApi.ashx/UnBindWXCustomerAccount?openid=" + openId + "&type=customer" + "&appid=" + appid;
  377. string getText = LYFZ.WinAPI.HttpClientHelper.GetResponse(APIUrlString);
  378. LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + APIUrlString + "” 接口返回信息:" + getText, appid, Global.LogsDongleDomainList);
  379. Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(getText);
  380. string code = jobject.GetValue("code").ToString();
  381. string content = "";
  382. if (code.Equals("200"))
  383. {
  384. content = "账号绑定已解除";
  385. }
  386. else
  387. {
  388. content = GetErrorMsg(jobject.GetValue("data").ToString(), openId, apiUrl, cid, appid);
  389. }
  390. return content;
  391. }
  392. /// <summary>
  393. /// 解除绑定员工
  394. /// </summary>
  395. /// <param name="openId"></param>
  396. /// <param name="apiUrl"></param>
  397. /// <param name="cid"></param>
  398. /// <param name="appid"></param>
  399. /// <returns></returns>
  400. public static string UnUserBinding(string openId, string apiUrl, int cid, string appid)
  401. {
  402. string APIUrlString = apiUrl + "/api/WXApi.ashx/UnBindWXCustomerAccount?openid=" + openId + "&type=user" + "&appid=" + appid;
  403. string getText = LYFZ.WinAPI.HttpClientHelper.GetResponse(APIUrlString);
  404. LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + APIUrlString + "” 接口返回信息:" + getText, appid, Global.LogsDongleDomainList);
  405. Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(getText);
  406. string code = jobject.GetValue("code").ToString();
  407. string content = "";
  408. if (code.Equals("200"))
  409. {
  410. content = "账号绑定已解除";
  411. }
  412. else
  413. {
  414. content = GetErrorMsg(jobject.GetValue("data").ToString(), openId, apiUrl, cid, appid);
  415. }
  416. return content;
  417. }
  418. }
  419. }