重構後的 CMPP30 類提供標準 .NET 異步模式(Begin/EndSend)、同步發送返回 CMPP_SUBMIT_RESP(獲取 MsgID),所有交互觸發 SMS 事件攜帶 SMS_EVENT 枚舉。
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,調用者無需通過事件匹配 MsgIDTask.Factory.FromAsync 轉為 TaskStart/Stop 單調用限制,避免狀態混亂基於 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]
[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);
}
封裝移動端發布的 dsmp.wsdl WebService,核心仍依賴 Provision 基類的 OnSyncOrderRelationReq 實現業務邏輯復用。
該實現提供標準化異步模式、直接返回響應、事件驅動交互、SOAP 接口抽象封裝四大工程級特性,可作為 CMPP 3.0 SP 端開發的參考架構。