using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace LYFZ.WeixinServers.WeiXinAPP
{
public class MicroMessageProcessing
{
public MicroMessageProcessing()
{
}
///
/// 微信输入信息内容绑定
///
///
///
///
///
///
///
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;
}
///
/// 客户评价
///
///
///
///
///
///
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;
}
///
/// 员工帐号绑定
///
///
///
///
///
///
public static string GetUserBinding(string openId, string apiUrl, int cid, string appid)
{
// retHref = "客户帐号绑定回复:CFZHBD#手机号#订单号后4位\n手机号和订单号点击这里,立即绑定\n\n"
//+"工作帐号绑定回复:YGZHBD#系统登录帐号#登录密码\n工作帐号点击这里,立即绑定\n\n";
return "工作帐号绑定回复:YGZHBD#系统登录帐号#登录密码\n工作帐号点击这里,立即绑定";
}
///
///
///
///
///
///
///
///
public static string GetAccountBinding(string openId, string apiUrl, int cid, string appid)
{
return "客户帐号绑定回复:CFZHBD#手机号#订单号后4位\n手机号和订单号点击这里,立即绑定";
}
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;
}
///
/// 员工帐号绑定
///
///
///
///
///
///
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;
}
///
/// 财务数据
///
///
///
///
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;
}
///
/// 客户会员绑定
///
///
///
///
///
///
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;
}
///
/// 解除绑定员工
///
///
///
///
///
///
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;
}
}
}