之前写的CMPP3.0未完成代码
来源:互联网 发布:成都多益网络面试通知 编辑:程序博客网 时间:2024/05/22 20:11
如题,参考大佬博客写的代http://blog.csdn.net/blin911/article/details/54344609,我自个因公司决策没继续往下写了,贴出来做分享参考
class Cmpp { // 设置项 public $host = ; public $port = ; public $Source_Addr = ; public $Shared_secret = ; public $SP_ID = ; public $SP_CODE = ; public $Service_Id = ; private $socket; private $Sequence_Id = 0; private $bodyData; private $AuthenticatorSource; public function createSocket(){ $socket = fsockopen( $this->host, $this->port, $errno, $errstr, 20 ); if(!$socket) $this->throwErr("can't create socket .", __LINE__); socket_set_timeout($socket, 1200); $this->socket = $socket; } public function CMPP_CONNECT(){ $Source_Addr = $this->Source_Addr; $Version = 0x30; $Timestamp = date('mdHis'); $AuthenticatorSource = $this->createAS($Timestamp); // 06 Octet String Source_Addr // 16 Octet String AuthenticatorSource // 01 Unsigned Integer Version // 04 Unsigned Integer Timestamp $bodyData = pack("a6a16CN", $Source_Addr, $AuthenticatorSource, $Version, $Timestamp); $this->AuthenticatorSource = $AuthenticatorSource; $this->send($bodyData, 0x00000001); } public function CMPP_CONNECT_RESP(){ // 04 Unsigned Integer Status // 16 Octet String AuthenticatorISMG // 01 Unsigned Integer Version $body = unpack("NStatus/a16AuthenticatorISMG/CVersion", $this->bodyData); // TODO ISMG认证失败,检查原因 // $this->cheakAISMG($body['Status'], $body['AuthenticatorISMG']); $this->Sequence_Id = $this->Sequence_Id + 1; } public function CMPP_SUBMIT($to, $text){ // 08 Unsigned Integer Msg_Id // 01 Unsigned Integer Pk_total // 01 Unsigned Integer Pk_number // 01 Unsigned Integer Registered_Delivery // 01 Unsigned Integer Msg_level // 10 Octet String Service_Id // 01 Unsigned Integer Fee_UserType // 32 Octet String Fee_terminal_Id // 01 Unsigned Integer Fee_terminal_type // 01 Unsigned Integer TP_pId // 01 Unsigned Integer TP_udhi // 01 Unsigned Integer Msg_Fmt // 06 Octet String Msg_src // 02 Octet String FeeType // 06 Octet String FeeCode // 17 Octet String ValId_Time // 17 Octet String At_Time // 21 Octet String Src_Id // 01 Unsigned Integer DestUsr_tl // * Octet String Dest_terminal_Id // 01 Unsigned Integer Dest_terminal_type // 01 Unsigned Integer Msg_Length // * Octet String Msg_Content $Msg_Id = 0; $Pk_total = 1; $Pk_number = 1; $Registered_Delivery = 0; $Msg_level = 0; $Service_Id = $this->Service_Id; $Fee_UserType = 2; $Fee_terminal_Id = ''; $Fee_terminal_type = 0; $TP_pId = 0; $TP_udhi = 0; $Msg_Fmt = 0; $Msg_src = $this->SP_ID; $FeeType = 03; $FeeCode = ""; $ValId_Time = ""; $At_Time = ""; $Src_Id = $this->SP_CODE; $DestUsr_tl = 1; $Dest_terminal_Id = $to; $Dest_terminal_type = 1; $Msg_Length = strlen($text); $Msg_Content = $text; $bodyData = pack( "a8CCCCa10Ca32CCCCa6a2a6a17a17a21Ca32CCa".$Msg_Length, $Msg_Id, $Pk_total, $Pk_number, $Registered_Delivery, $Msg_level, $Service_Id, $Fee_UserType, $Fee_terminal_Id, $Fee_terminal_type, $TP_pId, $TP_udhi, $Msg_Fmt, $Msg_src, $FeeType, $FeeCode, $ValId_Time, $At_Time, $Src_Id, $DestUsr_tl, $Dest_terminal_Id, $Dest_terminal_type, $Msg_Length, $Msg_Content ); $this->log([ $Msg_Id, $Pk_total, $Pk_number, $Registered_Delivery, $Msg_level, $Service_Id, $Fee_UserType, $Fee_terminal_Id, $Fee_terminal_type, $TP_pId, $TP_udhi, $Msg_Fmt, $Msg_src, $FeeType, $FeeCode, $ValId_Time, $At_Time, $Src_Id, $DestUsr_tl, $Dest_terminal_Id, $Dest_terminal_type, $Msg_Length, $Msg_Content]); $this->log($bodyData); $this->send($bodyData, 0x00000004); } public function CMPP_SUBMIT_RESP(){ // 08 Unsigned Integer Msg_Id // 04 Unsigned Integer Result $body = unpack("N2Msg_Id/NResult", $this->bodyData); $this->debug($this->bodyData, 1); } public function send($bodyData, $Command_Id){ $Total_Length = strlen($bodyData) + 12; $Sequence_Id = $this->Sequence_Id; // 04 Unsigned Integer Total_Length // 04 Unsigned Integer Command_Id // 04 Unsigned Integer Sequence_Id $headData = pack("NNN", $Total_Length, $Command_Id, $Sequence_Id); // 发送消息 $this->log("send $Command_Id"); fwrite($this->socket, $headData.$bodyData, $Total_Length); $this->listen($Sequence_Id); } public function listen($Sequence_Id){ // do{ if(feof($this->socket)){ $this->throwErr("socket was close .", __LINE__); } // 处理头 $headData = fread($this->socket, 12); if(empty($headData)){ $this->throwErr("can't get any data.", __LINE__); } $head = unpack("NTotal_Length/NCommand_Id/NSequence_Id", $headData); $this->log("get ".($head['Command_Id'] & 0x0fffffff)); // 处理body $this->bodyData = fread($this->socket, $head['Total_Length'] - 12); switch ( $head['Command_Id'] & 0x0fffffff ) { case 0x00000001: $this->CMPP_CONNECT_RESP(); break; case 0x00000004: $this->CMPP_SUBMIT_RESP(); break; default: $this->throwErr("unknow Command_Id .".$head['Command_Id'], __LINE__); break; } // } while ( $this->Sequence_Id != $Sequence_Id ); } /** * AuthenticatorSource = MD5(Source_Addr+9 字节的0 +shared secret+timestamp) * @param [type] $Timestamp [description] * @return [type] [description] */ public function createAS($Timestamp){ $temp = $this->Source_Addr . pack("a9","") . $this->Shared_secret . $Timestamp; return md5($temp, true); } /** * AuthenticatorISMG =MD5(Status + AuthenticatorSource + shared secret) * @param [type] $Status [description] * @param [type] $AuthenticatorISMG [description] * @return [type] [description] */ public function cheakAISMG($Status, $AuthenticatorISMG){ $temp = $Status . $this->AuthenticatorSource . $this->Shared_secret; $this->debug($temp.pack("a",""), 1, 1); $this->debug($AuthenticatorISMG.pack("a",""), 2, 1); if($AuthenticatorISMG != md5($temp, true)){ $this->throwErr("ISMG can't pass check .", __LINE__); } } public function log($data, $line = null){ if($line){ $data = $line . " : ".$data; } file_put_contents("./cmpp.log", print_r($data, true).PHP_EOL, FILE_APPEND); } public function debug($data, $fileName, $noExit = false){ file_put_contents("./$fileName.debug", print_r($data, true)); if(!$noExit) exit; } public function throwErr($info, $line){ die("info: $info in line :$line"); }}@unlink("./cmpp.log");$cmpp = new Cmpp;$cmpp->createSocket();$cmpp->CMPP_CONNECT();// $cmpp->CMPP_SUBMIT("xxxxxxxxx", '123');
简单说一下,因为时间太久了很多参数什么的我也忘了,只记得是调通了握手那里,其他的我也没做,当时只给了两天来着,代码应该也巨坑,我也没搞定就交给java仁兄了
阅读全文
1 0
- 之前写的CMPP3.0未完成代码
- 写代码之前的思考
- 写代码之前的工作
- CMPP3.0的java封装
- 写代码之前要做的准备
- 未完成的代码:Allchi_contraler
- 未完成的代码!
- CMPP3.0 状态报告出现的错误代码
- 整理之前写过的小代码,测试代码
- 要特别注意写代码之前的设计
- 没有Spring之前,代码原来是这样写的!
- 年终总结spring mvc 代码篇结合之前写的
- 关于前端写代码之前应该做到的事情
- 未完成的DNF外挂代码。
- CMPP3.0流程规范
- 移动cmpp3.0错误代码
- CMPP3.0-超长短信
- 基于CMPP3.0的企业短信网关API设计
- Maven初体验
- uboot移植:Flash分区和DDR分区
- 传输层协议——UDP协议
- 【MySQL】——常用两种数据引擎
- Swift中的选项集合
- 之前写的CMPP3.0未完成代码
- 高斯过程
- hadoop2.5 集群
- vim常用命令
- DrawerLayout侧滑菜单的简单实现
- 程序员应该访问的最佳网站
- uboot移植:uboot下的主Makefile解析
- Javascript—正则表达式
- Java虚拟机结构