payUrl == null) { $this->payUrl = Yii::$app->params['wanxin.payUrl']; //支付地址 } if ($this->merId == null) { $this->merId = Yii::$app->params['wanxin.merId']; //商户编码 } if ($this->secretKey == null) { $this->secretKey = Yii::$app->params['wanxin.key']; //商户密钥 } } /** * @param array $deposit * @param array $params * @return string */ public function outPay($deposit, $params = []) { $data = []; //请求参数的组装 $data['p0_Cmd'] = 'Buy'; //业务类型 $data['p1_MerId'] = $this->merId; //商户编码 $data['p2_Order'] = $deposit['order_sn']; //商户订单号 $data['p3_Amt'] = sprintf("%.2f",$deposit['rmb']); //订单总金额 $data['p4_Cur'] = 'CNY'; //交易币种 $data['p8_Url'] = $this->notifyUrl; //异步通知地址 $data['pd_FrpId'] = 'gateway'; //通道编码(网关支付) $data['pr_NeedResponse'] = '1'; //应答机制(固定值为1) $data['hmac'] = PayUtils::makeSign($data, $this->secretKey); // 签名 return static::createHtml($data, $this->payUrl); } /** * @param array $data * @return bool */ public function handleNotify($data) { if (PayUtils::checkSign($data, $this->secretKey)) { if (isset($data['r1_Code']) && $data['r1_Code'] == 1) { $merOrderId = trim($data['r6_Order']); /** @var Deposit $model */ $reuslt = Deposit::find()->where(['order_sn' => $merOrderId])->asArray()->limit(1)->one(); if ($reuslt['type'] != 1) { $res = Deposit::updateAll(['type' => 1], "order_sn = $merOrderId"); $configData = Config::find()->asArray()->one(); if ($configData['auto_deposit'] == 1 && $res) { $syncDespositModel = new SyncDesposit(); $syncDespositModel->login = $reuslt['login']; $syncDespositModel->amount = $reuslt['amount']; $syncDespositModel->comment = 'Deposit'; $syncDespositModel->memo = $merOrderId; $syncDespositModel->type = 2; $syncDespositModel->in_time = time(); $syncDespositModel->save(); } return true; } } } return false; } public function outNotify($success) { if ($success == true) { return "SUCCESS"; } else { return "FAIL"; } } /** * @param array $data * @return bool */ public function handleReturn($data) { if (PayUtils::checkSign( $data, $this->secretKey)) { if (isset($data['r1_Code']) && $data['r1_Code'] == 1) { $merOrderId = trim($data['r6_Order']); /** @var Deposit $model */ $model = Deposit::find()->where(['id' => $merOrderId])->asArray()->limit(1)->one(); if ($model) { return true; } } } return false; } public function outReturn($success) { } }