123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- namespace LYFZ.WeixinServers.WeiXinAPP
- {
- public class MicroMessageProcessing
- {
- public MicroMessageProcessing()
- {
-
- }
- /// <summary>
- /// 微信输入信息内容绑定
- /// </summary>
- /// <param name="functionCode"></param>
- /// <param name="openId"></param>
- /// <param name="apiUrl"></param>
- /// <param name="cid"></param>
- /// <param name="appid"></param>
- /// <returns></returns>
- public static string WeiXinMessageData(string functionCode, string openId, string apiUrl,int cid,string appid)
- {
- string retMsg = "";
- try
- {
- switch (functionCode)
- {
- case "KeywordQuery":
- retMsg = KeywordQuery(openId, apiUrl, cid, appid);
- break;
- case "AccountBinding":
- retMsg = CheckAccountBinding(openId, apiUrl, cid, appid);
- break;
- case "UserBinding":
- retMsg = CheckUserBinding(openId, apiUrl, cid, appid);
- break;
- case "AccountUnbind":
- retMsg = CustomerAccountUnbind(openId, apiUrl, cid, appid);
- break;
- case "UnUserBinding":
- retMsg = UnUserBinding(openId, apiUrl, cid, appid);
- break;
- case "OrderQuery":
- retMsg = CustomerOrderQuery(openId, apiUrl, cid, appid);
- break;
- case "MemberQuery":
- retMsg = CustomerMemberQuery(openId, apiUrl, cid, appid);
- break;
- case "FinancialBriefing":
- retMsg = SearchFinanceToday(openId, apiUrl, cid, appid);
- break;
- case "CustomerRating":
- retMsg = CustomerRating(openId,apiUrl, cid, appid);
- break;
- }
- }
- catch (Exception ex)
- {
- LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + apiUrl + "” 错误消息:" + ex.Message, appid, Global.LogsDongleDomainList);
- }
- if (String.IsNullOrEmpty(retMsg))
- {
- retMsg = "";
- }
- return retMsg;
- }
- /// <summary>
- /// 客户评价
- /// </summary>
- /// <param name="openId"></param>
- /// <param name="apiUrl"></param>
- /// <param name="cid"></param>
- /// <param name="appid"></param>
- /// <returns></returns>
- private static string CustomerRating(string openId, string apiUrl, int cid, string appid)
- {
- string msg = "";
- string APIUrlString = apiUrl + "/api/WXApi.ashx/GetCustomerOrderPushMsg?openid=" + openId + "&cusid=" + cid + "&appid=" + appid;
- msg = LYFZ.WinAPI.HttpClientHelper.GetResponse(APIUrlString);
- dynamic dyObjcet= Newtonsoft.Json.JsonConvert.DeserializeObject(msg);
- return dyObjcet.data;
- }
- public static string WeiXinMessageFastData(string functionCode,string msgData, string openId, string apiUrl, int cid, string appid)
- {
- string retMsg = "";
- try
- {
- switch (functionCode)
- {
-
- case "AccountBinding":
- retMsg = AccountBinding(openId, apiUrl, cid, appid, msgData);
- break;
- case "UserBinding":
- retMsg = UserBinding(openId, apiUrl, cid, appid, msgData);
- break;
- case "AccountUnbind":
- retMsg = AccountUnbind(openId, apiUrl, cid, appid, msgData);
- break;
- case "UnUserBinding":
- retMsg = UnUserBindingExE(openId, apiUrl, cid, appid, msgData);
- break;
- }
- }
- catch (Exception ex)
- {
- LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + apiUrl + "” 错误消息:" + ex.Message, appid, Global.LogsDongleDomainList);
- }
- if (String.IsNullOrEmpty(retMsg))
- {
- retMsg = "";
- }
- return retMsg;
- }
- private static string UnUserBindingExE(string openId, string apiUrl, int cid, string appid, string msgData)
- {
- string[] msgDataList = msgData.Split('#');
- string APIUrlString = apiUrl + "/api/WXApi.ashx/UnBindWXCustomerAccount?openid=" + openId + "&type=" + "user" + "&mobile=" + msgDataList[1] + "&appid=" + appid;
- string getText = LYFZ.WinAPI.HttpClientHelper.GetResponse(APIUrlString);
- LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + APIUrlString + "” 接口返回信息:" + getText, appid, Global.LogsDongleDomainList);
- Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(getText);
- string code = jobject.GetValue("code").ToString();
- string content = "";
- if (code.Equals("200"))
- {
- content = "解除绑定成功!";
- }
- else
- {
- content = "绑定失败,失败信息:" + jobject.GetValue("data").ToString();
- }
- return content;
- }
- private static string AccountUnbind(string openId, string apiUrl, int cid, string appid, string msgData)
- {
- string[] msgDataList = msgData.Split('#');
- string APIUrlString = apiUrl + "/api/WXApi.ashx/UnBindWXCustomerAccount?openid=" + openId + "&type=" + "customer" + "&mobile=" + msgDataList[1] + "&appid=" + appid;
- string getText = LYFZ.WinAPI.HttpClientHelper.GetResponse(APIUrlString);
- LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + APIUrlString + "” 接口返回信息:" + getText, appid, Global.LogsDongleDomainList);
- Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(getText);
- string code = jobject.GetValue("code").ToString();
- string content = "";
- if (code.Equals("200"))
- {
- content = "解除绑定成功!";
- }
- else
- {
- content = "绑定失败,失败信息:" + jobject.GetValue("data").ToString();
- }
- return content;
- }
- private static string UserBinding(string openId, string apiUrl, int cid, string appid, string msgData)
- {
- string[] msgDataList = msgData.Split('#');
- string APIUrlString = apiUrl + "/api/WXApi.ashx/BindErpAccount?openid=" + openId + "&account=" + msgDataList[1] + "&password=" + msgDataList[2] + "&appid=" + appid;
- string getText = LYFZ.WinAPI.HttpClientHelper.GetResponse(APIUrlString);
- LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + APIUrlString + "” 接口返回信息:" + getText, appid, Global.LogsDongleDomainList);
- Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(getText);
- string code = jobject.GetValue("code").ToString();
- string content = "";
- if (code.Equals("200"))
- {
- content = "绑定成功!";
- }
- else
- {
- content = "绑定失败,失败信息:" + jobject.GetValue("data").ToString();
- }
- return content;
- }
- private static string AccountBinding(string openId, string apiUrl, int cid, string appid, string msgData)
- {
- string[] msgDataList = msgData.Split('#');
- string APIUrlString = apiUrl + "/api/WXApi.ashx/BindWXCustomerAccount?openid=" + openId + "&telePhone=" + msgDataList[1] + "&orderFourNumber=" + msgDataList[2] + "&appid=" + appid;
- string getText = LYFZ.WinAPI.HttpClientHelper.GetResponse(APIUrlString);
- LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + APIUrlString + "” 接口返回信息:" + getText, appid, Global.LogsDongleDomainList);
- Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(getText);
- string code = jobject.GetValue("code").ToString();
- string content = "";
- if (code.Equals("200"))
- {
- content = "绑定成功!";
- }
- else
- {
- content = "绑定失败,失败信息:" + jobject.GetValue("data").ToString();
- }
- return content;
- }
-
- /// <summary>
- /// 员工帐号绑定
- /// </summary>
- /// <param name="openId"></param>
- /// <param name="apiUrl"></param>
- /// <param name="cid"></param>
- /// <param name="appid"></param>
- /// <returns></returns>
- public static string GetUserBinding(string openId, string apiUrl, int cid, string appid)
- {
- // retHref = "客户帐号绑定回复:CFZHBD#手机号#订单号后4位\n手机号和订单号<a href=\"" + bindurl + "/WeiXinAPP/BondingAccount.aspx&openid=" + openId + "&dbType=cus\">点击这里,立即绑定</a>\n\n"
- //+"工作帐号绑定回复:YGZHBD#系统登录帐号#登录密码\n工作帐号<a href=\"" + bindurl + "/WeiXinAPP/UserBondingAccount.aspx&openid=" + openId + "&dbType=user\">点击这里,立即绑定</a>\n\n";
- return "工作帐号绑定回复:YGZHBD#系统登录帐号#登录密码\n工作帐号<a href=\"http://wx.lyfz.net/WeiXinAPP/BondingUser.aspx?openid=" + openId + "&cusid=" + cid.ToString() + "&appid=" + appid + "\">点击这里,立即绑定</a>";
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="openId"></param>
- /// <param name="apiUrl"></param>
- /// <param name="cid"></param>
- /// <param name="appid"></param>
- /// <returns></returns>
- public static string GetAccountBinding(string openId, string apiUrl, int cid, string appid)
- {
- return "客户帐号绑定回复:CFZHBD#手机号#订单号后4位\n手机号和订单号<a href=\"http://wx.lyfz.net/WeiXinAPP/BondingAccount.aspx?openid=" + openId + "&cusid=" + cid.ToString() + "&appid=" + appid + "\">点击这里,立即绑定</a>";
- }
- public static string GetErrorMsg(string errormsg,string openId, string apiUrl, int cid, string appid)
- {
- if (errormsg.Contains("未绑定"))
- {
- return errormsg + "\n" + GetUserBinding(openId,apiUrl, cid, appid)+"\n"
- + GetAccountBinding(openId, apiUrl, cid, appid);
- }
- else {
- return errormsg;
- }
- }
- public static string KeywordQuery(string openId, string apiUrl, int cid, string appid)
- {
- /*string cusRetInfo = " 订单查询:DDCX\n"
- + "会员查询:HYCX\n";
- endRetInfo = "客户帐号绑定回复:CFZHBD#手机号#订单号后4位\n";*/
- string retInfo = "发送以下代码查询相关业务:\n\n"
- + "订单查询:DDCX\n"
- + "会员查询:HYCX\n"
- + "客户帐号绑定回复:CFZHBD#手机号#订单号后4位\n"
- + "工作帐号绑定回复:YGZHBD#系统登录帐号#登录密码\n"
- + "今日财务查询:JRCWCX\n"
- + "解除绑定帐号:JCBDZH#手机号\n"
- + GetUserBinding(openId, apiUrl, cid, appid) + "\n"
- + GetAccountBinding(openId, apiUrl, cid, appid);
- return retInfo;
- }
- /// <summary>
- /// 员工帐号绑定
- /// </summary>
- /// <param name="openId"></param>
- /// <param name="apiUrl"></param>
- /// <param name="cid"></param>
- /// <param name="appid"></param>
- /// <returns></returns>
- public static string CheckUserBinding(string openId, string apiUrl, int cid, string appid)
- {
- string APIUrlString = apiUrl + "/api/WXApi.ashx/CheckWXUserAccount?openid=" + openId + "&appid=" + appid;
- string getText = LYFZ.WinAPI.HttpClientHelper.GetResponse(APIUrlString);
- LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + APIUrlString + "” 接口返回信息:" + getText, appid, Global.LogsDongleDomainList);
- Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(getText);
- string code = jobject.GetValue("code").ToString();
- string content = "";
- if (code.Equals("200"))
- {
- content = "账号已绑定,无需重复绑定!";
- }
- else
- {
- content = GetUserBinding(openId, apiUrl, cid, appid);
- }
- return content;
- }
- /// <summary>
- /// 财务数据
- /// </summary>
- /// <param name="openId"></param>
- /// <param name="cusModel"></param>
- /// <param name="context"></param>
- public static string SearchFinanceToday(string openId, string apiUrl,int cid, string appid)
- {
- string APIUrlString = apiUrl + "/api/WXApi.ashx/SearchFinanceToday?openid=" + openId + "&appid=" + appid;
- string getText = LYFZ.WinAPI.HttpClientHelper.GetResponse(APIUrlString);
- LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + APIUrlString + "” 接口返回信息:" + getText, appid, Global.LogsDongleDomainList);
- Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(getText);
- string code = jobject.GetValue("code").ToString();
- string content = "";
- if (code.Equals("200"))
- {
- content = jobject.GetValue("data").ToString();
- }
- else
- {
- content = GetErrorMsg(jobject.GetValue("data").ToString(),openId, apiUrl, cid, appid);
- //"账号绑定解除失败,失败原因:" + jobject.GetValue("data").ToString() + "";
- }
- return content;
- }
- public static string CustomerMemberQuery(string openId, string apiUrl, int cid, string appid)
- {
- string APIUrlString = apiUrl + "/api/WXApi.ashx/SearchCustomerData?openid=" + openId + "&appid=" + appid;
- string getText = LYFZ.WinAPI.HttpClientHelper.GetResponse(APIUrlString);
- LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + APIUrlString + "” 接口返回信息:" + getText, appid, Global.LogsDongleDomainList);
- Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(getText);
- string code = jobject.GetValue("code").ToString();
- string content = "";
- if (code.Equals("200"))
- {
- Newtonsoft.Json.Linq.JArray array = (Newtonsoft.Json.Linq.JArray)jobject.GetValue("data");
- ///发送模板数据
- if (array.Count > 0)
- {
- Newtonsoft.Json.Linq.JObject cusObject = (Newtonsoft.Json.Linq.JObject)array[0];
- content += "姓名:" + cusObject.GetValue("持卡人") + "\n";
- content += "电话:" + cusObject.GetValue("电话") + "\n";
- content += "性别:" + (cusObject.GetValue("性别").ToString() == "0" ? "男" : "女") + "\n";
- content += "会员卡号:" + (string.IsNullOrEmpty((string)cusObject.GetValue("会员卡号")) ? "未办理" : (string)cusObject.GetValue("会员卡号")) + "\n";
- content += "积分:" + cusObject.GetValue("积分") + "\n";
- content += "欠款:" + cusObject.GetValue("欠款") + "\n";
- content += "金额:" + cusObject.GetValue("金额") + "\n";
- content += "折扣:" + cusObject.GetValue("折扣") + "\n";
- }
- else
- {
- content = "当前客户没有数据";
- }
- }
- else
- {
- content = GetErrorMsg(jobject.GetValue("data").ToString(), openId, apiUrl, cid, appid);
- }
- return content;
- }
- public static string CustomerOrderQuery(string openId, string apiUrl, int cid, string appid)
- {
- string APIUrlString = apiUrl + "/api/WXApi.ashx/SearchCustomerOrder?openid=" + openId + "&appid=" + appid;
- string getText = LYFZ.WinAPI.HttpClientHelper.GetResponse(APIUrlString);
- LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + APIUrlString + "” 接口返回信息:" + getText, appid, Global.LogsDongleDomainList);
- Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(getText);
- string code = jobject.GetValue("code").ToString();
- string content = "";
- if (code.Equals("200"))
- {
- content = jobject.GetValue("data").ToString();
- ///发送模板数据
- }
- else
- {
- content = GetErrorMsg(jobject.GetValue("data").ToString(), openId, apiUrl, cid, appid);
- }
- return content;
- }
- /// <summary>
- /// 客户会员绑定
- /// </summary>
- /// <param name="openId"></param>
- /// <param name="apiUrl"></param>
- /// <param name="cid"></param>
- /// <param name="appid"></param>
- /// <returns></returns>
- public static string CheckAccountBinding(string openId, string apiUrl, int cid, string appid)
- {
- string APIUrlString = apiUrl + "/api/WXApi.ashx/CheckWXCustomerAccount?openid=" + openId + "&appid=" + appid;
- string getText = LYFZ.WinAPI.HttpClientHelper.GetResponse(APIUrlString);
- LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + APIUrlString + "” 接口返回信息:" + getText, appid, Global.LogsDongleDomainList);
- Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(getText);
- string code = jobject.GetValue("code").ToString();
- string content = "";
- if (code.Equals("200"))
- {
- content = "账号已绑定,无需重复绑定!";
- }
- else
- {
- content = GetAccountBinding(openId, apiUrl, cid, appid);
- }
- return content;
- }
- public static string CustomerAccountUnbind(string openId, string apiUrl, int cid, string appid)
- {
- string APIUrlString = apiUrl + "/api/WXApi.ashx/UnBindWXCustomerAccount?openid=" + openId + "&type=customer" + "&appid=" + appid;
- string getText = LYFZ.WinAPI.HttpClientHelper.GetResponse(APIUrlString);
- LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + APIUrlString + "” 接口返回信息:" + getText, appid, Global.LogsDongleDomainList);
- Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(getText);
- string code = jobject.GetValue("code").ToString();
- string content = "";
- if (code.Equals("200"))
- {
- content = "账号绑定已解除";
- }
- else
- {
- content = GetErrorMsg(jobject.GetValue("data").ToString(), openId, apiUrl, cid, appid);
- }
- return content;
- }
- /// <summary>
- /// 解除绑定员工
- /// </summary>
- /// <param name="openId"></param>
- /// <param name="apiUrl"></param>
- /// <param name="cid"></param>
- /// <param name="appid"></param>
- /// <returns></returns>
- public static string UnUserBinding(string openId, string apiUrl, int cid, string appid)
- {
- string APIUrlString = apiUrl + "/api/WXApi.ashx/UnBindWXCustomerAccount?openid=" + openId + "&type=user" + "&appid=" + appid;
- string getText = LYFZ.WinAPI.HttpClientHelper.GetResponse(APIUrlString);
- LYFZ.WXLibrary.CommonHandleClass.WriteLog("公众号AppID:" + appid + "请求API地址“" + APIUrlString + "” 接口返回信息:" + getText, appid, Global.LogsDongleDomainList);
- Newtonsoft.Json.Linq.JObject jobject = (Newtonsoft.Json.Linq.JObject)Newtonsoft.Json.JsonConvert.DeserializeObject(getText);
- string code = jobject.GetValue("code").ToString();
- string content = "";
- if (code.Equals("200"))
- {
- content = "账号绑定已解除";
- }
- else
- {
- content = GetErrorMsg(jobject.GetValue("data").ToString(), openId, apiUrl, cid, appid);
- }
- return content;
- }
-
- }
- }
|