• 银联扫码支付


    class UnionScanQrCode{

    protected $appId;
    protected $appKey;
    protected $mid;
    protected $tid;
    protected $fromCode;
    
    protected $authorization = 'OPEN-FORM-PARAM';
    protected $instMid = 'QRPAYDEFAULT';//扫码业务
    
    protected $nonce;
    protected $timestamp;
    protected $qrCodeId;
    protected $requestTimestamp;
    
    protected $local_url = 'http://58.247.0.18:29015';//测试环境
    protected $produce_url = 'https://api-mop.chinaums.com';//生产环境
    protected $pay_url = '/v1/netpay/bills/get-qrcode';
    protected $close_url = '/v1/netpay/bills/close-qrcode';
    protected $query_url = '/v1/netpay/bills/query';
    protected $query_info_url = '/v1/netpay/bills/query-qrcode-info';
    protected $url;
    
    //,$appId,$appKey,$mid,$tid,$fromCode
    public function __construct($local,$appId,$appKey,$mid,$fromCode,$tid)
    {
        $this->nonce = (string)rand();
        $this->timestamp = date('YmdHis');
        $this->requestTimestamp = date('Y-m-d H:i:s');
        //$this->qrCodeId = $this->generateCode();
        if ($local){
            $this->url = $this->local_url;
            $this->appId = '10037e6f6a4e6da4016a6284b4de000b';
            $this->appKey = '1eb243a54d1349098af435ae8fac290d';
            $this->mid = '898340149000035';
            $this->tid = '38557688';
            $this->fromCode = '1017';
        }else{
            $this->url = $this->produce_url;
            $this->appId = $appId;
            $this->appKey = $appKey;
            $this->mid = $mid;
            $this->fromCode = $fromCode;
            $this->tid = $tid;
        }
    }
    
    public function getUnionUrl($money,$qrCode,$notify_url,$order_sn)
    {
        $content = $this->generateData($money,$qrCode,$notify_url,$order_sn);
        $header = [
            'Content-Type: application/json; charset=utf-8',
            'Content-Length:' . strlen($content),
            'Authorization:'.$this->auth($content),
        ];
        $url=$this->url.$this->pay_url;
        return ['url'=>$url,'content'=>$content,'header'=>$header];
    }
    
    public function getCloseUrl($qrCode)
    {
        $content = $this->generateCloseData($qrCode);
        $header = [
            'Content-Type: application/json; charset=utf-8',
            'Content-Length:' . strlen($content),
            'Authorization:'.$this->auth($content),
        ];
        $url=$this->url.$this->close_url;
        return ['url'=>$url,'content'=>$content,'header'=>$header];
    }
    
    public function getQueryUrl($order_sn,$pay_time)
    {
        $content = $this->generateQueryData($order_sn,$pay_time);
        $header = [
            'Content-Type: application/json; charset=utf-8',
            'Content-Length:' . strlen($content),
            'Authorization:'.$this->auth($content),
        ];
        $url=$this->url.$this->query_url;
        return ['url'=>$url,'content'=>$content,'header'=>$header];
    }
    
    public function getQueryInfoUrl($order_sn)
    {
        $content = $this->generateQueryInfoData($order_sn);
        $header = [
            'Content-Type: application/json; charset=utf-8',
            'Content-Length:' . strlen($content),
            'Authorization:'.$this->auth($content),
        ];
        $url=$this->url.$this->query_info_url;
        return ['url'=>$url,'content'=>$content,'header'=>$header];
    }
    
    protected function signature($content){
        $str = bin2hex(hash('sha256', $content, true));
        return base64_encode(hash_hmac('sha256',"$this->appId$this->timestamp$this->nonce$str", $this->appKey, true));
    }
    
    protected function auth($content)
    {
        $signature = $this->signature($content);
        return 'OPEN-BODY-SIG AppId="'.$this->appId.'", Timestamp="'.$this->timestamp.'", Nonce="'.$this->nonce.'", Signature="'.$signature.'"';
    }
    
    public function generateData($money,$qrCode,$notify_url,$order_sn)
    {
        $data = [
            "requestTimestamp" => $this->requestTimestamp,
            "qrCodeId" => $order_sn,
            'billNo' => $qrCode,
            'billData' => date("Y-m-d",time()),
            "mid" => $this->mid,
            "tid" => $this->tid,
            "instMid" => $this->instMid,
            "totalAmount" => $money,
            'notifyUrl' => $notify_url,
        ];
        return json_encode($data,true);
    }
    
    public function generateCloseData($qrCode)
    {
        $data = [
            'qrCodeId' => $qrCode,
            'requestTimestamp' => $this->requestTimestamp,
            'mid' => $this->mid,
            'tid' => $this->tid,
            'instMid' => $this->instMid,
        ];
        return json_encode($data,true);
    }
    
    private function generateQueryData($order_sn,$pay_time)
    {
        $data = [
            'requestTimestamp' => $this->requestTimestamp,
            'mid' => $this->mid,
            'tid' => $this->tid,
            'instMid' => $this->instMid,
            'billNo' => $order_sn,
            'billDate' => date("Y-m-d",$pay_time)
        ];
        return json_encode($data,true);
    }
    
    private function generateQueryInfoData($order_sn)
    {
        $data = [
            'requestTimestamp' => $this->requestTimestamp,
            'qrCodeId' => $order_sn,
        ];
        return json_encode($data,true);
    }
    
    private function generateCode()
    {
        return $this->sn($this->fromCode);
    }
    
    }
  • 相关阅读:
    深挖 GIL锁
    numpy小入门
    IPython和Jupyter notebook
    LINUX+Vmware+SVN的配置和安装
    windows下使用火狐浏览器插件AutoProxy+MyEnTunnel+SSH访问海外站点(转)
    无法打开键: UNKNOWNComponentsBE1FB738077DBE490AF18C3B9B1A1EE8E5F5286B58B542741A00A0A9AA420B27
    如何将软件测试和数据库联系在一起(转)
    接口测试第十二课(fidller过滤)(转)
    android、IOS和手机基础知识
    广州女生手机被偷 里面的身份证出卖了支付宝密码丨丢手机后必做6件事(转)
  • 原文地址:https://www.cnblogs.com/hubudong/p/14913200.html
Copyright © 2020-2023  润新知