首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

基於 CMPP 3.0 協議 SP 端實現(二):核心 API 設計與 Provision 接口支持

     編輯:關於C語言

CMPP30 核心類 API 設計

重構後的 CMPP30 類提供標準 .NET 異步模式(Begin/EndSend)、同步發送返回 CMPP_SUBMIT_RESP(獲取 MsgID),所有交互觸發 SMS 事件攜帶 SMS_EVENT 枚舉。

關鍵 API 簽名


public class CMPP30
{
    public event EventHandler SMS;
    
    public CMPP30(string spid, string password, string address, int port);
    public void Start();
    public void Stop();
    
    // 同步發送:返回提交響應含 MsgID
    public CMPP_SUBMIT_RESP Send(CMPP_SUBMIT submit);
    public CMPP_SUBMIT_RESP Send(string text, CEncoding encoding, 
        string sourceId, string[] destinations, string serviceId,
        bool needReport, FeeType feeType, FeeUserType feeUserType,
        string feeUser, bool realUser, int informationFee, string linkId);
    
    // 標準異步模式
    public IAsyncResult BeginSend(CMPP_SUBMIT submit, AsyncCallback cb, object state);
    public IAsyncResult BeginSend(string text, ..., AsyncCallback cb, object state);
    public CMPP_SUBMIT_RESP EndSend(IAsyncResult ar);
}

設計亮點

  • Send 直接返回 CMPP_SUBMIT_RESP,調用者無需通過事件匹配 MsgID
  • 異步模式符合 .NET APM 標準,可配合 Task.Factory.FromAsync 轉為 Task
  • Start/Stop 單調用限制,避免狀態混亂

Provision 正向訂購/取消接口

基於 SOAP/WebService 實現 SyncOrderRelationReq/Resp 交互。提供抽象基類 Provision : WebService,ASMX 後台繼承並實現 OnSyncOrderRelationReq 即可。

核心抽象方法簽名


protected abstract void OnSyncOrderRelationReq(
    string id, AddressInfo sendAddr, AddressInfo destAddr,
    UserID feeUserID, UserID destUserID, string linkID,
    int actionID, int actionReasonID, string spid, string serviceID,
    int accessMode, byte[] featureStr, out int hResult);

WebMethod 自動路由


[WebMethod]
[SoapDocumentMethod("sim.SyncOrderRelation", 
    RequestElementName = "SyncOrderRelationReq",
    ResponseElementName = "SyncOrderRelationResp")]
public void SyncOrderRelationReq(
    ref string Version, ref string MsgType,
    AddressInfo Send_Address, AddressInfo Dest_Address,
    UserID FeeUser_ID, UserID DestUser_ID,
    string LinkID, int ActionID, int ActionReasonID,
    string SPID, string SPServiceID, int AccessMode,
    byte[] FeatureStr, out int hRet)
{
    Version = "1.5.0"; MsgType = "SyncOrderRelationResp";
    OnSyncOrderRelationReq(..., out hRet);
}

Provision 反向訂購支持

封裝移動端發布的 dsmp.wsdl WebService,核心仍依賴 Provision 基類的 OnSyncOrderRelationReq 實現業務邏輯復用。

總結

該實現提供標準化異步模式、直接返回響應、事件驅動交互、SOAP 接口抽象封裝四大工程級特性,可作為 CMPP 3.0 SP 端開發的參考架構。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved