ComplianceServer/oldcode/CRMServices/PkgSms/InterfaceExec/QYXS.cs

128 lines
5.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text;
using System.Web;
using WX.CRM.CRMServices.SMS;
using WX.CRM.CRMServices.SMS.InterfaceModel;
namespace WX.CRM.CRMServices.PkgSms.InterfaceExec
{
/// <summary>
/// 企业信使
/// </summary>
internal class QYXS : IMsgSend
{
string userid = "";
string account = "";
string pwd = "";
string url = "";
public QYXS(string _userid = "", string _account = "", string _password = "")
{
WX.CRM.CRMServices.PkgSms.InterfaceModel.QYXSConfig config = new InterfaceModel.QYXSConfig();
userid = config.userid;
account = config.account;
pwd = config.pwd;
url = config.url;
if (!string.IsNullOrEmpty(_userid) && !string.IsNullOrEmpty(_account) && !string.IsNullOrEmpty(_password))
{
userid = _userid;
pwd = _password;
account = _account;
}
}
public SMS.InterfaceModel.ReturnResult Execute(string[] mobiles, string msg)
{
return Send(mobiles, msg);
}
public decimal queryAmt()
{
throw new NotImplementedException();
}
#region
WX.CRM.CRMServices.SMS.InterfaceModel.ReturnResult Send(string[] mobiles, string msg)
{
string mobilesStr = string.Join(",", mobiles);
WX.CRM.CRMServices.SMS.InterfaceModel.ReturnResult result = new WX.CRM.CRMServices.SMS.InterfaceModel.ReturnResult();
result.SendStr = "";
try
{
Encoding myEncoding = Encoding.GetEncoding("UTF-8");
String sResult = "";
//string param = string.Format("userid={0}&password=123456&account=优智能&mobile=13397149125,15902700620,18627671006,13212305006,15815865975&content=感谢您成为优智能的注册用户您的手机号将绑定我们高端信息服务稍后我们客服人员将以0731-88736777对您进行回访祝您投资顺利&action=send"
// , account
// );
//string param = string.Format("username={0}&pass={1}&mobile={2}&content={3}"
// , HttpUtility.UrlEncode(account)
// , Common.Utility.EncryptMD5(pwd)
// , mobilesStr
// , HttpUtility.UrlEncode(msg)
// );
string param = string.Format("userid={0}&account={1}&password={2}&mobile={3}&content={4}&action=send"
, userid
, account
, pwd
, mobilesStr
, msg
);
result.SendStr = param;
//byte[] postBytes = Encoding.ASCII.GetBytes(param);
byte[] postBytes = Encoding.GetEncoding("UTF-8").GetBytes(param);
//http://116.255.238.170:8768/sms.aspx
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded;";
req.ContentLength = postBytes.Length;
Stream webStream = req.GetRequestStream();
webStream.Write(postBytes, 0, postBytes.Length);
webStream.Close();
HttpWebResponse webResponse = (HttpWebResponse)req.GetResponse();
StreamReader reader = new StreamReader(webResponse.GetResponseStream(), myEncoding);
sResult = reader.ReadToEnd();
reader.Close();
sResult.Trim();
sResult = HttpUtility.UrlDecode(sResult);
result.ReturnStr = sResult;
if (!string.IsNullOrEmpty(sResult))
{
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(sResult);
//得到XML文档根节点
System.Xml.XmlElement root = doc.DocumentElement;
System.Xml.XmlNodeList nodeList = root.ChildNodes;
Dictionary<string, string> dic = new Dictionary<string, string>();
foreach (System.Xml.XmlNode node in nodeList)
{
dic.Add(node.Name, node.InnerText);
}
if (dic["returnstatus"].ToLower() == SubmitStatus.success.ToString())
{
result.submitStatus = SubmitStatus.success;
}
else
{
result.submitStatus = SubmitStatus.fail;
Common.LogHelper.Error(string.Format("QYXS.Send: sendStr:{0}; returnStr:{1}", result.SendStr, result.ReturnStr));
}
}
}
catch (Exception ex)
{
result.submitStatus = WX.CRM.CRMServices.SMS.InterfaceModel.SubmitStatus.fail;
Common.LogHelper.Error("QYXS.Send:" + ex.Message + ex.StackTrace);
}
return result;
}
public class res
{
public bool result { get; set; }
public string retcode { get; set; }
}
#endregion
}
}