Пример #1
0
 public function setResponse(array $responseArr, $isBackend = false)
 {
     $cmdId = isset($responseArr[self::PARAM_CMDID]) && $responseArr[self::PARAM_CMDID] ? $responseArr[self::PARAM_CMDID] : null;
     $chkValue = isset($responseArr[self::PARAM_CHKVALUE]) && $responseArr[self::PARAM_CHKVALUE] ? $responseArr[self::PARAM_CHKVALUE] : null;
     if ($cmdId && $chkValue) {
         $vSignFieldsOrd = isset($this->vSignOrder[$cmdId]) ? $this->vSignOrder[$cmdId] : null;
         if ($vSignFieldsOrd) {
             //Check Sign
             $vSignMessage = '';
             for ($i = 0; $i < count($vSignFieldsOrd); $i++) {
                 $field = $vSignFieldsOrd[$i];
                 $value = isset($responseArr[$field]) && $responseArr[$field] ? trim(urldecode($responseArr[$field])) : null;
                 if ($value) {
                     $vSignMessage .= $value;
                 }
             }
             if ($this->_vSign($vSignMessage, $chkValue)) {
                 foreach ($responseArr as $k => $v) {
                     if ($k == self::PARAM_MERPRIV) {
                         $v = json_decode(base64_decode(urldecode($v)), true);
                         if ($isBackend) {
                             $v['return'] = 'backend';
                         }
                     }
                     $this->response[$k] = $v;
                 }
                 Log::cnpnr($this->response);
             } else {
                 exit('验签失败');
             }
         }
     }
     return $this;
 }
Пример #2
0
 public static function cnpnr(array $response)
 {
     if ($response && is_array($response)) {
         $type = -1;
         $merPriv = isset($response[ChinaPNR::PARAM_MERPRIV]) ? $response[ChinaPNR::PARAM_MERPRIV] : null;
         $command = isset($response[ChinaPNR::PARAM_CMDID]) && $response[ChinaPNR::PARAM_CMDID] ? $response[ChinaPNR::PARAM_CMDID] : null;
         $identity = null;
         $identityValue = null;
         if ($merPriv && is_array($merPriv)) {
             $identity = isset($merPriv[ChinaPNR::PARAM_PRIVATE_SHOWID]) && $merPriv[ChinaPNR::PARAM_PRIVATE_SHOWID] ? $merPriv[ChinaPNR::PARAM_PRIVATE_SHOWID] : $identity;
             $identityValue = isset($response[$identity]) && $response[$identity] ? $response[$identity] : $identityValue;
         }
         $log = new Log();
         $log->setAttribute('source_id', self::TYPE_CNPNR);
         $keyCode = $merPriv ? implode('|', $merPriv) : null;
         if ($keyCode) {
             $log->setAttribute('key_code', $keyCode);
         }
         if ($command) {
             $log->setAttribute('command', $command);
         }
         if ($identity) {
             $log->setAttribute('identity', $identity);
         }
         if ($identityValue) {
             $log->setAttribute('identity_value', $identityValue);
         }
         if ($response[ChinaPNR::RESP_CODE] == '000') {
             $type = 0;
         }
         $log->setAttribute('type', $type);
         $log->setAttribute('status_code', $response[ChinaPNR::RESP_CODE]);
         $log->setAttribute('message', urldecode($response[ChinaPNR::RESP_DESC]));
         $log->setAttribute('data', json_encode($response));
         $log->save();
     }
 }