| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace common\pay\kexing;
- use backend\models\RemitOrder;
- use common\helpers\Utils;
- use common\pay\BaseRemitHandler;
- use Yii;
- use yii\helpers\VarDumper;
- use yii\httpclient\Client;
- class RemitHandler extends BaseRemitHandler
- {
- public $payUrl;
- public $merId;
- public $pubCert;
- public $priCert;
- /**
- * @inheritdoc
- */
- public function init()
- {
- parent::init();
- if ($this->payUrl == null) {
- $this->payUrl = Yii::$app->params['kexing.payUrl'];
- }
- if ($this->merId == null) {
- $this->merId = Yii::$app->params['kexing.merId'];
- }
- if ($this->pubCert == null) {
- $this->pubCert = __DIR__ . '/cert/1005314_pub.pem';
- }
- if ($this->priCert == null) {
- $this->priCert = __DIR__ . '/cert/1005314_prv.pem';
- }
- }
- /**
- * @param array $remitOrder
- * @param array $params
- * @return array
- */
- public function outRemit($remitOrder, $params = [])
- {
-
- $data = [
- 'version' => '1.0.0',
- 'productId' => '8001',
- 'transType' => 'PROXY_PAY',
- 'merNo' => $this->merId,
- 'orderDate' => date("Ymd"), //交易日期
- 'orderNo' => $remitOrder['remit_no'], //订单号
- 'notifyUrl' => $this->notifyUrl,
- 'transAmt' => $remitOrder['amount'] * 100, //分为
- 'commodityName' => $remitOrder['remit_no'], //产品名称
- //'phoneNo' => '',
- 'cardNo' => $remitOrder['bank_card_no'], // 银行账号
- 'cardName' => $remitOrder['payee_name'],
- //'cerdId' => '',
-
- ];
- $data['signature'] = PayUtils::makeSign($data, $this->priCert);
- Yii::warning('退款请求参数,' . VarDumper::dumpAsString($data), __METHOD__);
- $respon = PayUtils::sendPost($this->payUrl, $data);
- Yii::warning('退款返回结果,' . VarDumper::dumpAsString($respon), __METHOD__);
- $result = [];
- $temp = json_decode($respon,true);
- Yii::warning('退款返回参数1,' . VarDumper::dumpAsString($temp), __METHOD__);
-
- if ($temp['respCode'] == 'P000') {
- $result['pay_status'] = RemitOrder::STATUS_PAY_OUTER_PROCESS; // 外部打款中
- }
- $result['remit_no'] = trim($temp['orderNo']); // 打款单号
- $result['ret_code'] = trim($temp['respCode']); // 返回状态码
- $result['ret_msg'] = $temp['respDesc']; // 返回信息描述
- Yii::warning('退款返回参数2,' . VarDumper::dumpAsString($result), __METHOD__);
- return $result;
- }
- /**
- * @param array $data
- * @return bool
- */
- public function handleNotify($data)
- {
- Yii::warning('退款异步通知参数,' . VarDumper::dumpAsString($data), __METHOD__);
- if (PayUtils::verify($data, $this->pubCert)) {
- if (isset($data['respCode']) && $data['respCode'] == '0000' ) {
- $merOrderId = trim($data['orderNo']);
- /** @var RemitOrder $model */
- $model = RemitOrder::findByRemitNo($merOrderId);
- if ($model) {
- $model->type = 1;
- $model->save(false);
- return true;
- }
- }
- }
- return false;
- }
- public function outNotify($success)
- {
- if ($success == true) {
- return "success";
- } else {
- return "fails";
- }
- }
- }
|