| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- <?php
- namespace common\pay\eagle;
- use backend\models\Config;
- use backend\models\Deposit;
- use backend\models\SyncDesposit;
- use backend\models\Member;
- use backend\helpers\MailHelper;
- use common\pay\BasePayHandler;
- use Yii;
- use yii\helpers\VarDumper;
- class PayHandler extends BasePayHandler
- {
- public $payUrl; //网关地址
- public $merId; //mid
- public $privateKey; //商户私钥
-
- /**
- * @inheritdoc
- */
- public function init()
- {
- parent::init();
- if ($this->payUrl == null) {
- $this->payUrl = Yii::$app->params['eagle.payUrl']; //网关地址
- }
- if ($this->merId == null) {
- $this->merId = Yii::$app->params['eagle.merId']; //商户号码
- }
- if ($this->privateKey == null) {
- $this->privateKey = Yii::$app->params['eagle.Key']; //商户私钥
- }
-
- }
- /**
- * @param array $deposit
- * @param array $params
- * @return string
- */
- public function outPay($deposit, $params = [])
- {
- $data['merchId'] = $this->merId; //商户号码
- $data['time'] = time(); //交易时间
- $data['userId'] = $params['login']; //用户唯一标识
- $data['coin'] = 'USDT'; //订单号码
- $data['sign'] = PayUtils::makeSign($data,$this->privateKey);
- $result = PayUtils::sendPost($this->payUrl.'recharge_address', $data); //发送数据
- // 对返回的数据进行转化
- $result_array = json_decode($result,true);
- $member_id = $params['member_id']; // 通过用户id拿到用户的信息 获取到用户的邮箱地址
- $tt = print_r($result_array,true);
- file_put_contents('1101.txt',$tt);
-
- if($result_array['code']==0){
- $res = Member::updateAll(['address1' => $result_array['data'][0]['address']], "id = $member_id");
- return PayHandler::createGetHtml($this->payUrl,$result_array['data'][0]['address']);
- }else{
- return $result_array['message'];
- }
- }
- /**
- * @param array $data
- * @return bool
- */
- public function handleNotify($data)
- {
- $string = print_r($data,true);
- file_put_contents('postshuju.txt',$string);
- if (isset($data['sign']) && trim($data['sign']) !== '') {
-
- if (PayUtils::checkSign($data,$this->privateKey)) {
- file_put_contents('huidiao.txt','验签成功');
- if ($data['respCode'] == '00') {
- $merOrderId = trim($data['orderId']); //data函数
- $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;
- }else{
- return false;
- }
- }
- }
- return false;
- }
- public function outNotify($success)
- {
- if ($success == true) {
- return "ok";
- } else {
- return "fail";
- }
- }
- /**
- * @param array $data
- * @return bool
- */
- public function handleReturn($data)
- {
- //Yii::warning('支付同步通知参数,' . VarDumper::dumpAsString($data), __METHOD__);
- if (isset($data['sign']) && trim($data['sign']) !== '') {
-
- if (PayUtils::checkSign($data,$this->privateKey)) {
- if ($data['respCode'] == '00') {
- $merOrderId = trim($data['orderId']);
- $reuslt = Deposit::find()->where(['order_sn' => $merOrderId])->asArray()->limit(1)->one();
- if ($reuslt) {
- return true;
- }
- }
- }
- }
- return false;
- }
- public function outReturn($success)
- {
- }
- // 生成html模板文件
- public static function createGetHtml($url,$address2)
- {
- $html = <<<eot
- <div style="border: 1px solid green;width:800px;height: 400px;margin:10% auto;text-align: center;border-radius:30px;padding-top:70px; ">
- <h4>重要通知</h4>
- <p>你的钱包绑定成功.</p>
- <span style="color:red;" id="address2"></span>
- </div>
- <script src="/ui/js/jquery.1.9.1.min.js"></script>
- <script src="/ui/js/jquery-qrcode-0.14.0.min.js"></script>
- <script>
-
- $('#address2').qrcode({
- render: "canvas",
- width: 100,
- height: 100,
- text: "{$url}{$address2}"
- });
- </script>
- eot;
- return $html;
- }
-
- }
|