$data['partner_id'], //商户号 'currency' => 'CNY', //订单货币 'coin_code' => $data['pay_attr_code'], //支付币种 'amount' => $data['money'], //支付金额 'order_id' => $data['order_sn'], //订单号 'product_name' => "CJ", //商品名 'date' => date('Y-m-d H:i:s'), //支付时间 'notify_url' => $data['notify_url'], 'redirect_url' => $data['pay_url'], ]; $payInfo['signature'] = strtoupper(md5($this->getSign($payInfo) . "key=" . $this->publicKey)); $sRes = $this->httpPost($this->payUrl, $payInfo); if (empty($sRes)) { $this->_lastError = '请求异常'; payLogger(__CLASS__,'请求异常data=' . $sRes, $payInfo); return ''; } $aRes = json_decode($sRes, true); if (empty($aRes)) { $this->_lastError = '请求异常!'; payLogger(__CLASS__,'请求异常=' . $sRes, $payInfo); return ''; } if ((isset($aRes['code']) && $aRes['code'] != 200) || $aRes['data']['status'] != self::STATUS_CODE) { $this->_lastError = '请求异常,请求失败'; payLogger(__CLASS__,'请求异常,请求失败 data=' . $sRes, $payInfo); return ''; } return $aRes['data']['pay_url']; } public function queryOrder($data, &$orderSn, &$money, $partnerId) { $queryInfo = [ 'merchant_code' => $partnerId, 'order_id' => $orderSn ]; $queryInfo['signature'] = strtoupper(md5($this->getSign($queryInfo) . "key=" . $this->publicKey)); $sRes = $this->httpPost($this->queryUrl, $queryInfo); if (empty($sRes)) { $this->_lastError = '查询请求异常'; payLogger(__CLASS__,'查询请求异常 $queryInfo='.json_encode($queryInfo),$data); } $aRes = json_decode($sRes, true); if (empty($sRes)) { $this->_lastError = '查询解析异常'; payLogger(__CLASS__,'查询解析异常 data=' . $sRes, $data); return ''; } if ($aRes['data']['status'] != self::STATUS_CODE) { $this->_lastError = '查询订单状态异常'; payLogger(__CLASS__,'查询订单状态异常 data=' . $sRes, $data); return ''; } if ($money != $aRes['data']['amount']) { $this->_lastError = '查询订单金额异常'; payLogger(__CLASS__,'查询订单金额异常 data='.$sRes,$data); return ''; } return true; } public function notify(&$orderSn, &$tradeNo, &$money, $partnerId) { $data = request()->all()['data']; if ((isset($aRes['code']) && $aRes['code'] != 200) || (isset($aRes['status']) && $aRes['status'] != self::STATUS_CODE)) { payLogger(__CLASS__,'回调订单状态失败',$data); return false; } $info = [ 'merchant_code' => $partnerId, 'status' => $data['status'], 'order_id' => $data['order_id'], 'amount' => $data['amount'], 'currency' => $data['currency'], 'coin_amount' => $data['coin_amount'], 'coin_code' => $data['coin_code'], 'merchant_order_sn' => $data['merchant_order_sn'], ]; $sign = strtoupper(md5($this->getSign($info) . "key=" . $this->publicKey)); if ($sign != $data['signature']) { $this->_lastError = '验证失败!'; logger(json_encode($data) . ':验证失败!'); return false; } $money = $data['amount']; $res = $this->queryOrder($data, $data['merchant_order_sn'], $money, $partnerId); if (empty($res)) { return ''; } $orderSn = $data['merchant_order_sn']; $tradeNo = $data['order_id']; return true; } public function stopNotify() { return 'SUCCESS'; } }