标签:ack har verify ons 网站 数字 asp 表示 tor
第三方短信接口,支付接口广泛应用于金融领域与电商领域,这是我在14年工作时的一些经验总结,现在分享出来,希望能对一部分朋友有所帮助!
一:对接短信接口
对接短信接口大体分为两个步骤:
1. 根据接口文档发送短信类容到短信网关;
2. 回调结果并获取短信剩余条数
考虑到一个网站可能不止一个短信网关,我使用了工厂设计模式,下面附上代码
短信网关接口
/// <summary> /// 短信网关接口 /// </summary> public interface ISMS { /// <summary> /// 短信商 /// </summary> SMSProvider Provider { get; } /// <summary> /// 发送短信 /// </summary> /// <param name="destnumbers">要发送到的手机号码</param> /// <param name="msg">要发送的内容</param> /// <param name="sendTime">发送时间 为null表示立刻发送</param> int Send(string destnumbers, string msg, out SMSStatus status, DateTime? sendTime = null); /// <summary> /// 获取余额 /// </summary> int Balance(); /// <summary> /// 获取上行短信内容 /// </summary> /// <returns>返回null表示没有获取到上行短信</returns> List<SMSReply> GetReply(); }
短信工厂类
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; using System.IO; using System.ComponentModel; using SP.Studio.IO; using SP.Studio.Core; namespace SP.Studio.Gateway.SMS { /// <summary> /// 短信工厂 /// </summary> public class SMSFactory { public static ISMS CreateSMS(SMSConfig config) { ISMS sms = null; sms = (ISMS)Activator.CreateInstance(Type.GetType("SP.Studio.Gateway.SMS." + config.Provider), config.UserName, config.Password); return sms; } } /// <summary> /// 短信提供商 /// </summary> public enum SMSProvider : byte { /// <summary> /// 无供应商 /// </summary> None, /// <summary> /// 单元科技 /// </summary> [Description("单元科技")] CCell, /// <summary> /// 单元科技 接口2 /// </summary> [Description("单元科技")] CCell2, /// <summary> /// 亿美科技 /// </summary> [Description("亿美科技")] EMay, /// <summary> /// /// <summary> /// 中国网建 /// </summary> [Description("中国网建")] WebChinese, /// <summary> /// 国都 /// </summary> [Description("国都")] Guodu, /// <summary> /// 企信通(鑫阳创投) /// </summary> [Description("企信通")] YDQXT, /// <summary> /// http://sdk.entinfo.cn:8061/ /// </summary> [Description("DXC")] DXC, /// <summary> /// 凌凯科技 http://www.zhongguowuxian.com/Item/list.asp?id=1460 /// </summary> [Description("凌凯科技")] LingKai, /// <summary> /// 玄武科技 /// </summary> [Description("玄武科技")] MT, /// <summary> /// 单元科技新接口 /// </summary> [Description("单元科技-3")] CCell3, /// <summary> /// 使用短信猫发送 /// </summary> [Description("短信猫")] Modem = 100 } /// <summary> /// 短信息配置类 /// </summary> public class SMSConfig { public SMSProvider Provider { get; set; } public string UserName { get; set; } public string Password { get; set; } } }
实例
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web; using SP.Studio.Net; using SP.Studio.Text; using SP.Studio.Security; using SP.Studio.Web; namespace SP.Studio.Gateway.SMS { public class LingKai : SMSBase, ISMS { public LingKai(string userName, string password) : base(userName, password) { } public SMSProvider Provider { get { return SMSProvider.LingKai; } } public int Send(string destnumbers, string msg, out SMSStatus status, DateTime? sendTime = null) { if (!WebAgent.IsMobile(destnumbers)) { status = SMSStatus.Number; return 0; } string url = string.Format("http://sdk.zhongguowuxian.com:98/ws/BatchSend.aspx?CorpID={0}&Pwd={1}&Mobile={2}&Content={3}&Cell=&SendTime=", this.UserName, this.Password, destnumbers, HttpUtility.UrlEncode(msg, Encoding.GetEncoding("GB2312"))); string result = NetAgent.DownloadData(url, Encoding.GetEncoding("GB2312")); //大于等于0的数字,发送成功(得到大于等于0的数字、作为取报告的id);-1、帐号未注册;-2、其他错误;-3、密码错误;-4、手机号格式不对;-5、余额不足;-6、定时发送时间不是有效的时间格式; //-7、请在提交信息末尾添加中文企业签名【】; -8、发送内容需在1到500个字之间;-9、 发送号码为空 this.SaveGateway(result); status = SMSStatus.Success; long code; if (long.TryParse(result, out code)) { switch (code) { case -1: case -3: status = SMSStatus.Account; break; case -2: case -6: status = SMSStatus.Other; break; case -4: case -9: status = SMSStatus.Number; break; case -5: status = SMSStatus.Money; break; case -7: case -8: status = SMSStatus.Message; break; } } else { status = SMSStatus.Other; } return status == SMSStatus.Success ? 1 : 0; } /// <summary> ///获取短信的剩余量 /// </summary> /// <returns></returns> public int Balance() { string url = string.Format("http://sdk.zhongguowuxian.com:98/WS/SelSum.aspx?CorpID={0}&Pwd={1}", this.UserName, this.Password); string result = NetAgent.DownloadData(url,Encoding.GetEncoding("GB2312")); int balance; int.TryParse(result, out balance); return balance; } public List<SMSReply> GetReply() { return new List<SMSReply>(); } } }
二:对接支付接口
对接支付接口大体步骤也分为两步,部分支付厂商可能存在小差异
1. 找到合适的支持厂商,签订协议,拿到商户code与签名私钥;
2. 根据提供对接文档Post数据跳转到支付网关;
3. 支付回调结果并验证商户网页(一般做法是把回调地址传给网关,在回调地址中验证支付结果)
下面附上部分代码
public override bool Verify(VerifyCallBack callback) { #region ========= DEBUG ========== StringBuilder sb = new StringBuilder(); sb.AppendLine(DateTime.Now + "\n"); foreach (var keyValue in this.GetRequestGet()) { sb.AppendFormat("{0}:{1}\t", keyValue.Key, keyValue.Value); } sb.AppendLine().AppendLine("------------------------"); if (HttpContext.Current != null) System.IO.File.AppendAllText(HttpContext.Current.Server.MapPath("~/App_Data/Alipay.log"), sb.ToString(), Encoding.UTF8); #endregion SortedDictionary<string, string> inputPara = this.GetRequestGet(); string notify_id = WebAgent.GetParam("notify_id"); string sign = WebAgent.GetParam("sign"); string status = WebAgent.GetParam("trade_status"); Dictionary<string, string> sPara = this.FilterPara(inputPara); string preSignStr = this.CreateLinkString(sPara); if (this.Sign(preSignStr) != sign) return false; if (!string.IsNullOrEmpty(notify_id)) { string veryfy_url = VERYFYURL + "partner=" + this.Partner + "¬ify_id=" + notify_id; if (NetAgent.DownloadData(veryfy_url, Encoding.GetEncoding(_input_charset)) != "true") return false; } bool isSuccess = false; switch (status) { case "TRADE_SUCCESS": // 高级即时到帐状态下 case "TRADE_FINISHED": // 普通即时到帐状态下 case "WAIT_SELLER_SEND_GOODS": // 担保交易 等待卖家发货 isSuccess = true; break; default: isSuccess = false; break; } if (isSuccess) callback.Invoke(); return isSuccess; }
PS:扫描下方二维码或点击链接,加入QQ群
标签:ack har verify ons 网站 数字 asp 表示 tor
原文地址:https://www.cnblogs.com/ydcnblog/p/9257901.html