95 lines
3.5 KiB
C#
95 lines
3.5 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Web;
|
|
using WX.CRM.CRMServices.PkgSms.InterfaceModel;
|
|
using WX.CRM.CRMServices.SMS;
|
|
using WX.CRM.CRMServices.SMS.InterfaceModel;
|
|
|
|
namespace WX.CRM.CRMServices.PkgSms.InterfaceExec
|
|
{
|
|
internal class upCat : IMsgSend
|
|
{
|
|
string account = "";
|
|
string pwd = "";
|
|
string url = "";
|
|
public upCat(string _account = "", string _password = "")
|
|
{
|
|
upCatConfig config = new InterfaceModel.upCatConfig();
|
|
account = config.account;
|
|
pwd = config.pwd;
|
|
url = config.url;
|
|
if (!string.IsNullOrEmpty(_account) && !string.IsNullOrEmpty(_password))
|
|
{
|
|
pwd = _password;
|
|
account = _account;
|
|
}
|
|
}
|
|
public SMS.InterfaceModel.ReturnResult Execute(string[] mobiles, string msg)
|
|
{
|
|
return Send(mobiles, msg);
|
|
}
|
|
|
|
public decimal queryAmt()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
#region
|
|
ReturnResult Send(string[] mobiles, string msg)
|
|
{
|
|
string mobilesStr = string.Join("|", mobiles);
|
|
ReturnResult result = new ReturnResult();
|
|
result.SendStr = "";
|
|
try
|
|
{
|
|
Encoding myEncoding = Encoding.GetEncoding("UTF-8");
|
|
String sResult = "";
|
|
string param = string.Format("username={0}&pass={1}&mobile={2}&content={3}"
|
|
, HttpUtility.UrlEncode(account)
|
|
, WX.CRM.Common.Utility.EncryptMD5(pwd)
|
|
, mobilesStr
|
|
, HttpUtility.UrlEncode(msg)
|
|
);
|
|
result.SendStr = param;
|
|
byte[] postBytes = Encoding.ASCII.GetBytes(param);
|
|
//byte[] postBytes = Encoding.GetEncoding("UTF-8").GetBytes(param);
|
|
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;
|
|
|
|
res info = WX.CRM.Common.Utility.JSONToObject<res>(result.ReturnStr);
|
|
if (info != null)
|
|
result.submitStatus = info.result == true ? SMS.InterfaceModel.SubmitStatus.success : SMS.InterfaceModel.SubmitStatus.fail;
|
|
else
|
|
throw new Exception("反序列化异常,返回值:" + result.ReturnStr);
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result.submitStatus = SubmitStatus.fail;
|
|
WX.CRM.Common.LogHelper.Error("upCat.Send:" + ex.Message + ex.StackTrace);
|
|
}
|
|
return result;
|
|
}
|
|
public class res
|
|
{
|
|
public bool result { get; set; }
|
|
public string retcode { get; set; }
|
|
}
|
|
#endregion
|
|
}
|
|
}
|