<?php

    namespace app\business;

    use support\Db;
    use support\Redis;
    use yzh52521\EasyHttp\Http;

    class PayThreeBusiness
    {


        static private $url="http://mi.feicuipay.com/optimus/collect/placeOrder";
        static private $apikey='bbe90c3a0ebb0c0a13f2c526a5c2543b';
        static private $memberid='107912662';

        /**
         * @param array $param[
         * order_no
         * ]
         * @return array
         */
        static public function payment($order_no,$pay_bankcode,$money,$url = '')
        {
            if (empty($url)) {
                $url = getenv('WEB_HOST');
            }
            $arr         = [
                'method'              => 'placeOrder',
                'timestamp'           => date('Y-m-d H:i:s'),
                'memberId'            => (int)self::$memberid,//商户号
                'channelCode'         => $pay_bankcode,//通道类型
                'callerOrderId'       => (string)$order_no,//商户订单号
                'amount'              => (int)bcmul($money, 100),//金额，单位为分
                'merchantCallbackUrl' => (string)getenv('API_HOST') . '/api/pay/payment_callback_three.html',//异步通知地址，支付成功后将支付成功消息以POST请求发送给这个网址
                'returnUrl'           => (string)$url
            ];
            $arr['sign'] = self::payMd5sign($arr);
            $data        = Http::asJson()->post(self::$url, $arr)->array();
            return ['data' => $data, 'arr' => $arr];
        }

        static public function payMd5sign(array $param)
        {
            ksort($param);                               //ASCII码排序
            $md5str = '';
            foreach ($param as $key => $val) {
                $md5str = $md5str. $key  . $val;
            }
            $md5str = self::$apikey.$md5str.self::$apikey;
            //获取sign
            $sign = md5($md5str);
            //转换成字符串并且拼接上密钥
            return $sign;

        }


    }