12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace Jiaruan;
- class ProtoLogin {
-
-
- public function proc( $req ){
- //检查签名
- if($req->sign != $this->sign_req($req) ){
- log_error('check sign failed ' . json_encode($req));
- return $this->create_resp($req,1);
- }
- else{
- log_debug('check sign success ' . json_encode($req));
- return $this->create_resp($req,0);
- }
- }
-
-
- private function sign_req( $req ){
- $str = $req->type;
- $str.= $req->msgid;
- $str.= $req->model;
- $str.= $req->mac;
- $str.= $req->sn;
- $str.= $req->version;
- $str.= $req->wip;
- $str.= $req->nmode;
- $str.= $req->rssi;
- $str.= $req->serialnum;
- $str.= $req->uptime;
- $str.= C('协议签名密钥');
- return strtoupper(md5(urlencode($str)));
- }
-
-
- private function sign_resp( $resp ){
- $str = $resp['type'];
- $str.= $resp['msgid'];
- //$str.= $resp['result'];
- $str.= C('协议签名密钥');
- return strtoupper(md5(urlencode($str)));
- }
-
-
- public function create_resp( $req, $result ){
- $resp = array(
- 'type' => 2,
- 'msgid' => $req->msgid,
- 'mac' => $req->mac,
- 'sign' => '',
- 'result' => $result,
- );
- $resp['sign'] = $this->sign_resp($resp);
- return $resp;
- }
-
- }
|