$this->merchant_no, "bankCode" => 'WXPAY', "orderNo" => $order_no, "orderAmount" => $pay_amount, "notifyUrl" => $notify_url, "returnUrl" => $return_url, "goodsInfo" => $goodsInfo, ); // 取业务参数的json串 $serviceJson = json_encode($bizParam); // 对json进行AES加密 $serviceParam = Security::encrypt($serviceJson, $this->md5Key); // 对AES后的参数 serviceParam 进行 md5 加签, 注意输出格式必须是字节形式 $plainText = $serviceParam . $this->md5Key; $md5Res = md5($plainText, true); // 对md5后的结果进行 base64, 作为签名 $sign = base64_encode($md5Res); // 作为post请求body的参数 $param = array( "serviceParam" => $serviceParam, "sign" => $sign ); $date = date("yymdHis"); // 设置请求头 $header = array( "requestId: " . $date . $this->uuid(), "timestamp: " . $date, // yyyyMMddHHmmss "version: " . "1.0", "service: " . $service, "appId: " . $this->merchant_no ); $postRes = HTTPRequester::HTTPPost($this->url, $param, $header); $resJson = json_decode($postRes); $resServiceParam = $resJson->serviceParam; $resSign = $resJson->sign; // 校验响应签名 $checkSign = $this->checkSign($resServiceParam, $this->md5Key, $resSign); // 签名通过方可认为请求正常 if ($checkSign) { $resServiceJson = Security::decrypt($resServiceParam, $this->md5Key); $list = json_decode($resServiceJson, true); return $list; } else{ return false; } } public function notifyVerify($data){ $resServiceParam = $data['serviceParam']; $resSign = $data['sign']; // 校验响应签名 $checkSign = $this->checkSign($resServiceParam, $this->md5Key, $resSign); // 签名通过方可认为请求正常 if ($checkSign) { $resServiceJson = Security::decrypt($resServiceParam, $this->md5Key); $list = json_decode($resServiceJson, true); return $list; } else{ return false; } } public function queryOrder($order_no) { $service = "payonline.order.query"; // 请求的方法 service 值,根据实际值填写 // 请求的业务参数,根据实际填写 $bizParam = array( "merNo" => $this->merchant_no, "orderNo" => $order_no, "transType" => "01", ); // 取业务参数的json串 $serviceJson = json_encode($bizParam); // 对json进行AES加密 $serviceParam = Security::encrypt($serviceJson, $this->md5Key); // 对AES后的参数 serviceParam 进行 md5 加签, 注意输出格式必须是字节形式 $plainText = $serviceParam . $this->md5Key; $md5Res = md5($plainText, true); // 对md5后的结果进行 base64, 作为签名 $sign = base64_encode($md5Res); // 作为post请求body的参数 $param = array( "serviceParam" => $serviceParam, "sign" => $sign ); $date = date("yymdHis"); // 设置请求头 $header = array( "requestId: " . $date . $this->uuid(), "timestamp: " . $date, // yyyyMMddHHmmss "version: " . "1.0", "service: " . $service, "appId: " . $this->merchant_no ); $postRes = HTTPRequester::HTTPPost($this->url, $param, $header); $resJson = json_decode($postRes); $resServiceParam = $resJson->serviceParam; $resSign = $resJson->sign; // 校验响应签名 $checkSign = $this->checkSign($resServiceParam, $this->md5Key, $resSign); // 签名通过方可认为请求正常 if ($checkSign) { $resServiceJson = Security::decrypt($resServiceParam, $this->md5Key); return $resServiceJson; } else{ return false; } } function uuid($prefix = '') { $chars = md5(uniqid(mt_rand(), true)); $uuid = substr($chars,0,8); $uuid .= substr($chars,8,4); $uuid .= substr($chars,12,4); $uuid .= substr($chars,16,1); return $prefix . $uuid; } function checkSign($serviceParam, $md5Key, $sign) { $md5Res = md5($serviceParam . $md5Key, true); return base64_encode($md5Res) === $sign; } }