| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- namespace common\pay\huiying;
- use backend\models\Config;
- use backend\models\Deposit;
- use backend\models\SyncDesposit;
- use common\pay\BasePayHandler;
- use Yii;
- use yii\helpers\VarDumper;
- class PayHandler extends BasePayHandler
- {
- public $payUrl;
- public $merId;
- public $comkey;
- /**
- * @inheritdoc
- */
- public function init()
- {
- parent::init();
- if ($this->payUrl == null) {
- $this->payUrl = Yii::$app->params['huiying.payUrl'];
- }
- if ($this->merId == null) {
- $this->merId = Yii::$app->params['huiying.merId'];
- }
- if ($this->comkey == null) {
- $this->comkey = Yii::$app->params['huiying.key'];
- }
- }
- /**
- * @param array $deposit
- * @param array $params
- * @return string
- */
- public function outPay($deposit, $params = [])
- {
- $data['p0_Cmd'] = 'Buy';
- $data['p1_MerId'] = $this->merId;
- $data['p2_Order'] = $deposit['order_sn'];
- $data['p3_Amt'] = $deposit['rmb'];
- $data['p4_Cur'] = "CNY";
- $data['p5_Pid'] = $deposit['order_sn'];
- $data['p6_Pcat'] = $deposit['order_sn'];
- $data['p7_Pdesc'] = $deposit['order_sn'];
- $data['p8_Url'] = 'http://pay.sure-stock.com/pay/notify/9';
- $data['p9_SAF'] = "0";
- $data['pa_MP'] = $deposit['order_sn'];
- $data['pd_FrpId'] = $params['bankCode'];
- $data['pr_NeedResponse'] = "1";
-
- Yii::warning('支付请求参数,' . VarDumper::dumpAsString($data), __METHOD__);
- #调用签名函数生成签名串
- $hmac = PayUtils::getReqHmacString($data, $this->merId, $this->comkey);
- $data['hmac'] = $hmac;
- $result = static::createHtml($data, $this->payUrl);
- Yii::warning('支付请求结果,' . VarDumper::dumpAsString($result), __METHOD__);
- return $result;
- }
- /**
- * @param array $data
- * @return bool
- */
- public function handleNotify($data)
- {
- Yii::warning('支付异步通知参数,' . VarDumper::dumpAsString($data), __METHOD__);
- # 解析返回参数.
- $bRet = PayUtils::CheckHmac($data, $this->merId, $this->comkey);
- # 校验码正确.
- if($bRet){
- if($data['r1_Code'] == "1" && $data['r9_BType'] == "2"){
- $merOrderId = trim($data['r6_Order']);
- $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)
- {
- return $this->handleNotify($data);
- }
- public function outReturn($success)
- {
- }
- }
|