config = $config; $this->client = new PCCashier(); } public function pay($order) { try { // 参数 $this->client->body = $order ; $apiMap=$this->client->apiMap(); $form = ''; $postData = $this->client->postData($this->config, $apiMap['index']['method']); $url = $this->config['apiUrl'] . $apiMap['index']['url']; $form = '
'; foreach ($postData as $k => $v) { $form .= "{$k}

"; } $form .= '
'; return $form; } catch (\Exception $e) { \Yii::error(FormatHelper::exception($e, __METHOD__)); $this->error = $e->getMessage(); return false; } } public function notify($post) { try{ $this->client->verify($this->config, $post['data'], $post['sign']); return [ 'out_trade_no' => $post['data']['orderCode'], //商户订单号 'trade_no' => $post['data']['tradeNo'], //汇聚平台流水号 'pay_fee' => bcmul(intval($post['data']['totalAmount']), 0.01, 2), // 000000000001 ]; }catch(\Exception $e){ \Yii::error(FormatHelper::exception($e, __METHOD__)); $this->error = $e->getMessage(); return false; } } public function refund($info) { $amount = str_pad((string) intval(bcmul($info['refund_amount'], 100)), 12, '0', STR_PAD_LEFT); $this->client->body = [ "orderCode" => $info['out_trade_no'], "oriOrderCode" => $info['refund_order_no'], "refundAmount" => $amount, "notifyUrl" => \Yii::getAlias('@apiUrl').'/notify/sandpay-fast-refund', "refundReason" => mb_substr($info['refund_reason'],0,60), "refundMarketAmount" => "", "extend" => "" ]; try { $method = 'orderRefund'; $ret = $this->client->request($this->config, $method); // $apiMap =$this->client->apiMap(); $this->client->verify($this->config, $ret['data'], $ret['sign']); // $postData = $this->client->postData($this->config, $apiMap[$method]['method']); // $postData['data']= Json::decode($postData['data']); $data = Json::decode($ret['data']); if($data["respCode"] == '000000'){ //退款失败 throw new \Exception($data['respMsg'] ?? $ret); } return true; } catch (\Exception $e) { throw new \Exception($e->getMessage().'请稍后重新发起交易,或联系汇聚客服'); } } }