| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653 |
- <?php
- namespace app\utils;
- /**
- *
- * Created by PhpStorm.
- * User: admin
- * Date: 2017/8/18
- * Time: 17:50
- */
- class LgApi
- {
- public $apiUrl;
- public $method;
- public $setting;
- public $store_id;
- public static $key;
- /**
- * 配置信息
- * @param $host
- * @param $port
- */
- public function __construct($store_id = 1)
- {
- $this->store_id = $store_id;
- $store_info = \app\models\Store::find()->where(['id'=>$this->store_id])->one();
- if ($store_info){
- $setting = [
- 'version'=>'1.0',
- 'mchid'=>$store_info['lg_mch_id'],//mchid
- 'projectCode'=>$store_info['lg_project_code'],//ProjectCode
- 'parkcode'=>$store_info['lg_park_code'],//parkcode
- 'pkey'=>$store_info['lg_pkey'],//公钥
- 'key'=>$store_info['lg_key'],//私钥
- ];
- self::$key = $store_info['lg_key'];
- }else{
- $setting = [
- 'version'=>'1.0',
- 'mchid'=>'1836965269132984320',//mchid
- 'ProjectCode'=>'1836966182916636673',//ProjectCode
- 'parkcode'=>'1744896567810359296',//parkcode
- 'pkey'=>'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApwAXBcCJq4W/iPq8wAp0N9tpEsMQ0kh+BFuMXoOiNEpHaXB9/CfR+5aPr+w1lRsjvQwY5noMdeXs58u8w1nqdazLMlquMP1tPfh9XVit46b4VPJT/dGsjOQAOkgFrgejo3IGyDGzDeBh4QWqJGz2HzNp3E+wLIoe+lMNKbxaO0XYiJBp6Gbu+pIIdsTDxiKhYINOaCjgWx9ebeLmhmIy5+i2jGlKeq4Nn+9EDnSXjhoem5nYOJFpwW8wutJk8dG9RetEHPQ6emnfV2RyAqSA9LndUx66QTegqSMKbU+j5HSREFIIjEUGsxsqEVjeyfnjL5t/RmPfTMWNUlw24nquLQIDAQAB',//平台公钥
- 'key'=>'MIIEpAIBAAKCAQEAyIH6QWzz0ZwBUqM7GVeL4kBZkedcV7NRZZtABtm157q5omSQAKMbJjVe65G1Cy0igP5A9Ax8Cg7kWlGgR/AkL/UZJmDiUx+uyumGVyEINS+/irtVSo0vdsXhLYQyrnOqCleX3Pnf8JZvSDLBY8E3TY7fyFNnx53YDpMIaKRyyrPdSIDHjfxWxSsC9CYWtsRrCW9BeBVKaYvHFw1seYnZOrCdA076g0w7I6BB+GOU37gThoBQSAK/D2pHjQ5Vnz1gQYgzSdqCCG8+jlvsS18Rms06U/UlIZ5y8b97J6SdN0NQcLncAB971PPae+KCI3DYdmhey8NFH8vJYEq5p2qVTQIDAQABAoIBADHYokLGl7yp2GhXXRdZPNTT45CSoFHLKfalCF9Lm13O/VxCPMxzwAmZJg5RLF1pbJT94F7rhaCogBt2BG8t44kqmQSB/HHmw/j84iFh/FzgkHEoTjVY8Q5Jdkfu//x/k6u7h+zvD72LYIHl4E7w11NILBjspzWoZ3CEHAiLrV/3s0M8vRnTu17CPAscikrTUmPQ1eZQAGlaAhAiRLIwJig32tcbp9IZUf7ea2LueChFDbYuVJrQPqB90+h08w3MNYLQXcIvQHqqKd2jQwyJkFhW/bCaW3pNCXrIb1TSGQLvZK3A1fTcYN9kPrji8s/toHNcCmHcNvFk5c75slQXcgECgYEA7sSxVs9yTBMOQunutgwlYTVYuepvs5TDFRVr+u2XKs9INcHv/AVXPYUdCWJf/cFv8ekZwPRJa/wh26B/clZr7VwKayWePfhJMq6oYq40+7eYHcCO3pDtfrGTGp2E3fS6KoNG7+RWUdzWfMCVdJrTF7eZ9RcpslgMU6rnRUMNZk0CgYEA1vpo/u2N7XZa5a6mIWSynPPhFEY95bAclkluxciN8wYFZ3vYnKcPMLLIiqv3jY2mgp8m5SneFd7VnjFJuFpzm39yYY1chYYSETAX9nGPSw2aYT0w1dblQ+rKplztafh3om7d5DOyAe3KIkfHNWIU55Rhy3K9BkBml9iz7DiHawECgYEA6r/z43fd1jG+CcfZ7J6QebxrWY7G9/bAvo/rNDA4OdzGECR3AH93wIKJg9p2qhRvLZaSvYTwUvz3hOmNpCqXviyKCcJYjHD59pyF7U99xCZDpqzVSrmO5stL6BUKtvaPupCLQ/xpad8H+muWBaja9iyLb86wLionJHOZIh3EpNkCgYAKq7FMfhQeZlKKtgmO/MWU3tIcRIRMA1rX5ts1vAe3uWPJSC9vTyeE3krv/ysxfod2UloG4/YfFcl6qa2kFfFJFaFi0DZ4djgtXDrEQ8y+B/XSv8vNwXXt0hiu+0vZh7jAekpPSnWafOgcnX142953xDi6dX6GcenlvZ7oqcGnAQKBgQDACgj+P0zpLVXPBmmgIkj470UN5IresWLh8sRFxZ/io7W7ie+8dR9Zh7alFp/TSpSmSUVdWVjbmpmwdBU/8aRkvpdGhQLu7vjBLGNwmP4NEkeMU5Tw75YrhaCw/Xhkz2RE7SwQVg4C0D9NrJeL+q23wA0fBylrtHf6MHZe/UifOw==',//商户私钥
- ];
- }
- $this->setting = $setting;
- }
- /**
- * author xiaohuihui <xzh_tx@163.com>
- * @param $url 请求的url
- * @param $option 发送的字段
- * @param int|array $header 发送的头信息
- * @param string $type 请求方法,默认post
- * @return mixed | array
- */
- public static function RequestCurlPay($url, $options=null, $header = [], $type = 'GET') {
- $curl = curl_init (); // 启动一个CURL会话
- curl_setopt_array($curl, array(
- CURLOPT_URL => $url,
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_SSL_VERIFYPEER => false,
- CURLOPT_SSL_VERIFYHOST => false,
- CURLOPT_ENCODING => '',
- CURLOPT_MAXREDIRS => 10,
- CURLOPT_TIMEOUT => 0,
- CURLOPT_FOLLOWLOCATION => true,
- CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
- CURLOPT_CUSTOMREQUEST => 'POST',
- CURLOPT_POSTFIELDS =>$options,
- CURLOPT_HTTPHEADER => $header,
- ));
- $response = curl_exec($curl);
- // print_r($response);die;
- curl_close($curl);
- return $response;
- }
- public static function doPost($url, $params, $charset){
- // dd($url);
- // dd($params);
- // $api = "https://apipcs3.dccnet.com.cn/api/jft/api/pay/add/h5/traceless/order/V2";
- // $curl = new Curl();
- // $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
- // $curl->get($api);
- // $res = $curl->response;
- // dd($res);
- // $res = json_decode($res, true);
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- "content-type: application/json"
- ));
- curl_setopt($ch, CURLOPT_POST, true);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS,8000);
- curl_setopt($ch, CURLOPT_TIMEOUT_MS, 30000);
- curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
- curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
- // 尝试使用这些选项来允许安全的重新协商
- // curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
- // curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'DEFAULT:@SECLEVEL=1');
- // curl_setopt($ch, CURLOPT_SSL_OPTIONS, CURLSSLOPT_ALLOW_BEAST);
- // curl_setopt($ch, CURLOPT_VERBOSE, true); // Enable verbose output
- // 尝试添加以下选项,确保不使用不安全的遗留重新协商
- // curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
- $response = curl_exec($ch);
- if ($response === false) {
- $error = curl_error($ch);
- $errno = curl_errno($ch);
- print_r($error);die;
- //dd("cURL Error: $error, Error Number: $errno");
- }
- $resinfo = curl_getinfo($ch);
- // dd($resinfo);
- curl_close($ch);
- // dd($response);
- if($resinfo["http_code"] != 200){
- throw new \Exception("response status code is not valid. status code: ".$resinfo["http_code"]);
- }
- return $response;
- }
- /**
- * RSA单独签名方法,未做字符串处理,字符串处理见getSignContent()
- * @param $data 待签名字符串
- * @param $privatekey 商户私钥,根据keyfromfile来判断是读取字符串还是读取文件,false:填写私钥字符串去回车和空格 true:填写私钥文件路径
- * @param $signType 签名方式,RSA:SHA1 RSA2:SHA256
- * @param $keyfromfile 私钥获取方式,读取字符串还是读文件
- * @return string
- * @author mengyu.wh
- */
- public static function alonersaSign($data, $privatekey, $signType = "RSA2", $keyfromfile = false)
- {
- if (!$keyfromfile) {
- $priKey = $privatekey;
- $res = "-----BEGIN RSA PRIVATE KEY-----\n" .
- wordwrap($priKey, 64, "\n", true) .
- "\n-----END RSA PRIVATE KEY-----";
- } else {
- $priKey = file_get_contents($privatekey);
- $res = openssl_get_privatekey($priKey);
- }
- ($res) or die('您使用的私钥格式错误,请检查RSA私钥配置');
- if ("RSA2" == $signType) {
- openssl_sign($data, $sign, $res, OPENSSL_ALGO_SHA256);
- } else {
- openssl_sign($data, $sign, $res);
- }
- if ($keyfromfile) {
- openssl_free_key($res);
- }
- $sign = base64_encode($sign);
- return $sign;
- }
- public static function verify($data, $sign, $publicKey, $signType = 'RSA')
- {
- $pubKey = $publicKey;
- $res = "-----BEGIN PUBLIC KEY-----\n" .
- wordwrap($pubKey, 64, "\n", true) .
- "\n-----END PUBLIC KEY-----";
- ($res) or die('支付宝RSA公钥错误。请检查公钥文件格式是否正确');
- //调用openssl内置方法验签,返回bool值
- if ("RSA2" == $signType) {
- $result = (bool)openssl_verify($data, base64_decode($sign), $res, OPENSSL_ALGO_SHA256);
- } else {
- $result = (bool)openssl_verify($data, base64_decode($sign), $res);
- }
- return $result;
- }
- //收款人信息进件,信息实名
- public function FlexibleRegister($post_data){
- $data['name'] = $post_data['name'];//收款人姓名
- $data['certCard'] = $post_data['certCard'];//收款人身份证
- $data['parkCodes'] = [$this->setting['parkcode']];
- $data['contractType'] = $post_data['contractType'];//签约方式 100 快捷签约
- $data['accNo'] = $post_data['accNo'];//银行卡号
- $data['bankCode'] = $post_data['bankCode'];//收款人银行编码(调用 1006 此接口)(特殊可选)
- $data['bankPhone'] = $post_data['bankPhone'];//预留手机号
- $idcardFront = saveTempFile($post_data['idcardFront'], 'jpg');
- $idcardBack = saveTempFile($post_data['idcardBack'], 'jpg');
- $data['idcardFront'] = $this->processImageUrl($idcardFront);//身份证正面
- $data['idcardBack'] = $this->processImageUrl($idcardBack);//身份证徽面
- $data['extendjson'] = "{}";//扩展参数
- $data['alipayAcc'] = "";//根据签约园区是否支持验证必填 支付宝账号
- $data['notifyUrl'] = pay_notify_url('lg/apply-notify', $this->store_id);//实名回调地址
- // $data['notifyUrl'] = 'http://id1103.com/index.php/lg/apply-notify/1';//实名回调地址
- $new_data = array();
- $new_data['mchid'] = $this->setting['mchid']??"1587293811556904960";
- $new_data['version'] = $this->setting['version']??"1.0";
- $new_data['tranCode'] = "1009";
- $new_data['timestamp'] = date("Y-m-d H:i:s");
- $new_data['nonceStr'] = mb_substr(md5(uniqid()),0,17);
- $new_data['signType'] = "RSA2";
- $new_data['tradeNo'] = $post_data['order_id']??uniqid();
- // var_dump($data);die;
- $new_data['bizContent'] = self::encrypt(json_encode($data));
- // $new_data2['bizContent'] = self::encrypt(json_encode(array(
- // "parkCode" => $this->setting['parkcode'],
- // )));
- // print_r($new_data);die;
- ksort($new_data);
- $data_decode = urldecode(http_build_query($new_data));
- $sign = self::alonersaSign($data_decode,$this->setting['key']);
- $new_data['sign'] = $sign;
- // $ss = "http://lgapi.vev.cn:8002/v1/api/flexible/register";
- $ss = "https://lgapi.dq.cn/v1/api/flexible/register";
- $s = json_encode($new_data);
- $ret = self::RequestCurlPay($ss,$s,array(
- "content-type: application/json"
- ),"POST");
- $_ret = json_decode($ret,true);
- if ($_ret['code'] != 10000){
- return [
- 'status'=>999,
- 'msg'=>$_ret['subMsg']
- ];
- }
- return json_decode(self::decrypt($_ret['bizContent']),true);
- }
- private function processImageUrl($imageUrl)
- {
- // 获取图片内容
- $imageContent = file_get_contents($imageUrl);
- // 检查文件大小是否小于 1MB
- if (strlen($imageContent) <= 1 * 1024 * 1024) {
- // 将文件内容转换为 Base64 编码
- $base64Encoded = base64_encode($imageContent);
- // 对 Base64 编码后的字符串进行 URL 编码
- $urlEncoded = urlencode($base64Encoded);
- return $urlEncoded;
- } else {
- // 判断$imageUrl是否为jpg,如果不是就转换为jpg, $imageUrl是一个本地路径
- $type = exif_imagetype($imageUrl);
- if ($type != IMAGETYPE_JPEG) {
- $image = imagecreatefromstring(file_get_contents($imageUrl));
- $newImagePath = tempnam(sys_get_temp_dir(), 'img_') . '.jpg';
- imagejpeg($image, $newImagePath);
- imagedestroy($image);
- $imageUrl = $newImagePath;
- }
- $imageUrl = Image::ImageSize($imageUrl, 1);
- return $this->processImageUrl($imageUrl);
- }
- }
- //收款人进件状态查询
- public function FlexibleQuery($post_data){
- $new_data = array();
- $data['certCard'] = $post_data['certCard'];//收款人身份证
- $data['parkCode'] = $this->setting['parkcode'];//收款人身份证
- $new_data['mchid'] = $this->setting['mchid']??"1587293811556904960";
- $new_data['version'] = $this->setting['version']??"1.0";
- $new_data['tranCode'] = "1010";
- $new_data['timestamp'] = date("Y-m-d H:i:s");
- $new_data['nonceStr'] = mb_substr(md5(uniqid()),0,17);
- $new_data['signType'] = "RSA2";
- $new_data['tradeNo'] = $post_data['order_id']??uniqid();
- $new_data['bizContent'] = self::encrypt(json_encode($data));
- ksort($new_data);
- $data = urldecode(http_build_query($new_data));
- $sign = self::alonersaSign($data,$this->setting['key']);
- $new_data['sign'] = $sign;
- // $ss = "http://lgapi.vev.cn:8002/v1/api/flexible/query";
- $ss = "https://lgapi.dq.cn/v1/api/flexible/query";
- $s = json_encode($new_data);
- $ret = self::RequestCurlPay($ss,$s,array(
- "content-type: application/json"
- ),"POST");
- $_ret = json_decode($ret,true);
- if ($_ret['code'] != 10000){
- return [
- 'status'=>999,
- 'msg'=>$_ret['subMsg']
- ];
- }
- return json_decode(self::decrypt($_ret['bizContent']),true);
- }
- //收款人银行卡号修改
- public function FlexibleMkd($post_data){
- $new_data = array();
- $data['certCard'] = $post_data['certCard'];//收款人身份证
- $data['accNo'] = $post_data['accNo'];//银行卡号
- $data['bankCode'] = $post_data['bankCode'];//银行编码
- $data['bankPhone'] = $post_data['bankPhone'];//预留手机号
- $data['alipayAcc'] = $post_data['alipayAcc'];//支付宝账号
- $new_data['mchid'] = $this->setting['mchid']??"1587293811556904960";
- $new_data['version'] = $this->setting['version']??"1.0";
- $new_data['tranCode'] = "1012";
- $new_data['timestamp'] = date("Y-m-d H:i:s");
- $new_data['nonceStr'] = mb_substr(md5(uniqid()),0,17);
- $new_data['signType'] = "RSA2";
- $new_data['tradeNo'] = $post_data['order_id']??uniqid();
- $new_data['bizContent'] = self::encrypt(json_encode($data));
- ksort($new_data);
- $data = urldecode(http_build_query($new_data));
- $sign = self::alonersaSign($data,$this->setting['key']);
- $new_data['sign'] = $sign;
- $ss = "https://lgapi.dq.cn/v1/api/flexible/mkd";
- $s = json_encode($new_data);
- $ret = self::RequestCurlPay($ss,$s,array(
- "content-type: application/json"
- ),"POST");
- $_ret = json_decode($ret,true);
- if ($_ret['code'] != 10000){
- return [
- 'status'=>999,
- 'msg'=>$_ret['subMsg']
- ];
- }
- return json_decode(self::decrypt($_ret['bizContent']),true);
- }
- // private static $key = "MIIEogIBAAKCAQEAnBEaoP5IiH5p1kfbe/9oK6IPKr+dlZQkaKlFy6c3/8ViDA+WFe6wOhDJLC0SaCmHmp+LNR7GniQhDRBWf3v4Fp2YzFAVCpgKTeaBMMwLogF+yp00C1JieJBV5fD6oD4sJEDpK9ksC1CUSftLO9eeH/2do9b6lzM6qHmLXOAKR0Cp+R26eCcEEXSiXCYCrBExlm83SzFGl++OVBHxz+oQhFfSaynPhy+Jr2hzUag655+Z8S2jcT82a/YQS89StOh9kkUL8hrOV0NWI965crA+JlJF/qp2iN2KEQwYTXUxZFLXVwV4jXW7iBmqiOuGRO0Eg1ji3PmW7b7LT39tRzCBNwIDAQABAoIBAAUOuaOXLSr3MpJvuH+9/1ZpC9kuMnrv1qo2ahbQ1j8jDcVar/NwAIsxLHb5BiXhl3P96mX2ffTb/0VltSSwE/ivplotcjEdfwZjpOYiID8uXmyBSBF7dWN3OFr/2/woNG5l7oIUQwAiEVwmzGfypqL39g08LaZYUg6DOdS9q4RmWVxZRng8RsEt2zkJ3xPMmO7A5UrwUozX2s110vp3bW1HIR2z1cbs8VTyAO/esG541h9G2s3oZUYx9zR3YZEh64an/UuMrzMj8Mr7OLFjk68bgD5qHUwUdb9tx6exakFHppzVyc8A+AoClVq+wMmY10KHE+6YDjxJG+U3hK8wvMECgYEA+3JFDxtUTdwRAHYQNFox7hQwXjQ7e9HRB1o4EVo7OO3CvYuyCj+dezh3VMTTOX+19R/9OneQTbsd8dkla6Jqk7WwyHm5z/ayE8pibhOvR7Au8sRCA7YCWsPv6MAsKAf9Em6TolBqLpthjYx2HKR5ZJfspZhltvXfPbuVZbguyOECgYEAnuSlLE0vBX4AF2NvHHHIIOVfgicuy9COq8AiSrEJFxlxw7LHLAHif0ELdYvK0d7Bbs1b16iPjAWT/Y+kkiCDFvIqb71IAAN4ddpjSSblix+qVZOo7Fn2CZYFRfaagLsQz1YWJl+eSgEQOzOnAqUBLa1H1Fel+epOqvlbnOrCFRcCgYAa/cIyA/IBxZzBmurUY9Y2Q06J3juAaB5zFpksK65txv//js5W0UtbXc1ZeSNfabkjjgKF0y3XWj21p2Sf8DhWkMtgScjLbSTigPgd7tkC7gOsJasccN5B1gSbzH0w8uKUpvAMHWu4gw9uvWQ0YOdzB+fsQrawdCY5nzhDSgkjoQKBgCZzJ/EvgEhw9C60tieI9SfYuaLyPmW9wziWlvXCH3QCiUAVHBNvJVMr90zrlhnxMJfSg/4M4Se+FdDPGMDvsykzUseVYz31mQnT3iDOk891yy9IOyFup5YsQnxqr3qlSe0SZOvGSbSYy0e4ORrvuPhHrVEaIKT4aS8AhoXTXUHjAoGAbm7lX7bLmGBkgEeiaSPWYEfSOTNwxpHvZpC3ccJjOujjAGqhljqtSxOvwRS302okSIRkdYH3xoc0gkPwhnC2Srm18tQpc4N8sIL7fBz7lpV5xoJ2Ye7MFejOkliRsWQpM3doy49NnwfJ2EzzpORA9ru2XXs4dNU+nQvkRAVbzDc=";
- //
- // private static $pkey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjKvj/70BMI1Y9sHSTTeUF40JYbUT7TRwyzF7puxyIzuRL03zn1aKGOeiDb9t6CEL2VdgZ7yI4jY9FSgknGr6yzilwQLvh+bvgaTFuZdY/os9S2otWnjPL+IQnFpLaIaoEQUZoZ3aV0D4n/gKupFj5GYnnlLnP+K2Wx1pN+XOZ7nEW8TuflaxRtkeJsUsbFjdFYqjBw/kjLWEndGMCn3qbgzreQFRYixNT7BM75hYEB3ZRq8b5T6UcU5Qsd8ssDdf7T7PA0mTzilCHSoIMx6phYhxG3bf/zudmSQR+6MLr2NbE0L/F4opb6EYY3uB9nWK5/uNQqJDnofD5atcBlJ3DwIDAQAB";
- //获取收款人银行卡信息
- public function FlexibleBanks(){
- $pay_data = array();
- $pay_data['mchid'] = $this->setting['mchid']??"1587293811556904960";
- $pay_data['version'] = $this->setting['version']??"1.0";
- $pay_data['tranCode'] = "1006";
- $pay_data['timestamp'] = date("Y-m-d H:i:s");
- $pay_data['nonceStr'] = mb_substr(md5(uniqid()),0,17);
- $pay_data['signType'] = "RSA2";
- $pay_data['tradeNo'] = $data['order_id']??uniqid();
- $pay_data['bizContent'] = self::encrypt(json_encode(array(
- "parkCode" => $this->setting['parkcode'],
- )));
- ksort($pay_data);
- $data = urldecode(http_build_query($pay_data));
- $sign = self::alonersaSign($data,$this->setting['key']);
- $pay_data['sign'] = $sign;
- // $ss = "http://lgapi.vev.cn:8002/v1/api/flexible/banks";
- $ss = "https://lgapi.dq.cn/v1/api/flexible/banks";
- $s = json_encode($pay_data);
- $ret = self::RequestCurlPay($ss,$s,array(
- "content-type: application/json"
- ),"POST");
- $_ret = json_decode($ret,true);
- $bizContent = json_decode(self::decrypt($_ret['bizContent']),true);
- return $bizContent;
- }
- //佣金发放
- public function FlexiblePay($post_data){
- $new_data = array();
- $data['outTradeNo'] = $post_data['outTradeNo'];//唯一批次号
- $data['projectCode'] = $this->setting['projectCode'];//项目编码【8812】创建时返回
- $data['parkCode'] = $this->setting['parkcode'];
- $data['currency'] ='CNY';//币种
- $data['amt'] = $post_data['accNo'];//发放总金额 单位分
- $payDetails = [
- [
- // 'tranflowCode' => $post_data['tranflowCode'],//交易明细流水号
- 'tranflowCode' => date('YmdHis') . sprintf('%07d', 1),
- 'channelType' => '1000',//支付类型,1000 -银行 1003 支付宝(需要园区是否支持而确定支付类型)
- 'amt' => $post_data['amt'],//发佣金额 单位分
- 'name' => $post_data['name'],//收款人姓名
- 'certCard' => $post_data['certCard'],//收款人证件号
- 'certType' => '1001',//证件类型
- 'extendjson' => "{}",//扩展参数
- ]
- ];
- $data['payDetails'] = $payDetails;//发佣明细
- $data['notifyUrl'] = pay_notify_url('lg/cash-notify', $this->store_id);//实名回调地址
- $data['extendjson'] = "{}";//扩展参数
- // print_r($data);die;
- debug_log($data);
- $new_data['mchid'] = $this->setting['mchid']??"1587293811556904960";
- $new_data['version'] = $this->setting['version']??"1.0";
- $new_data['tranCode'] = "8008";
- $new_data['timestamp'] = date("Y-m-d H:i:s");
- $new_data['nonceStr'] = mb_substr(md5(uniqid()),0,17);
- $new_data['signType'] = "RSA2";
- $new_data['tradeNo'] = $post_data['order_id']??uniqid();
- $new_data['bizContent'] = self::encrypt(json_encode($data));
- ksort($new_data);
- debug_log($new_data);
- $data = urldecode(http_build_query($new_data));
- $sign = self::alonersaSign($data,$this->setting['key']);
- $new_data['sign'] = $sign;
- // $ss = "http://lgapi.vev.cn:8002/v1/api/duqee/pay";
- $ss = "https://lgapi.dq.cn/v1/api/duqee/pay";
- $s = json_encode($new_data);
- $ret = self::RequestCurlPay($ss,$s,array(
- "content-type: application/json"
- ),"POST");
- $_ret = json_decode($ret,true);
- debug_log($_ret);
- if ($_ret['code'] != 10000){
- return [
- 'status'=>999,
- 'msg'=>$_ret['subMsg']
- ];
- }
- return json_decode(self::decrypt($_ret['bizContent']),true);
- }
- //佣金发放状态查询
- public function FlexiblePayQuery($post_data){
- $new_data = array();
- $data['outTradeNo'] = $post_data['outTradeNo'];//传入批次号
- $data['tranflowCode'] = $post_data['tranflowCode'];//交易明细流水号
- $data['parkCode'] = $this->setting['parkcode'];
- $new_data['mchid'] = $this->setting['mchid']??"1587293811556904960";
- $new_data['version'] = $this->setting['version']??"1.0";
- $new_data['tranCode'] = "8009";
- $new_data['timestamp'] = date("Y-m-d H:i:s");
- $new_data['nonceStr'] = mb_substr(md5(uniqid()),0,17);
- $new_data['signType'] = "RSA2";
- $new_data['tradeNo'] = $post_data['order_id']??uniqid();
- $new_data['bizContent'] = self::encrypt(json_encode($data));
- ksort($new_data);
- $data = urldecode(http_build_query($new_data));
- $sign = self::alonersaSign($data,$this->setting['key']);
- $new_data['sign'] = $sign;
- // $ss = "http://lgapi.vev.cn:8002/v1/api/duqee/pay/query";
- $ss = "https://lgapi.dq.cn/v1/api/duqee/pay/query";
- $s = json_encode($new_data);
- $ret = self::RequestCurlPay($ss,$s,array(
- "content-type: application/json"
- ),"POST");
- $_ret = json_decode($ret,true);
- if ($_ret['code'] != 10000){
- return [
- 'status'=>999,
- 'msg'=>$_ret['subMsg']
- ];
- }
- return json_decode(self::decrypt($_ret['bizContent']),true);
- }
- /**
- * 格式化公钥
- * @param $publicKey string 公钥
- * @return string
- */
- public static function formatterPublicKey($publicKey)
- {
- $res = "-----BEGIN PUBLIC KEY-----\n" .
- wordwrap($publicKey, 64, "\n", true) .
- "\n-----END PUBLIC KEY-----";
- return $res;
- }
- /**
- * 格式化私钥
- * @param $priKey string 私钥
- * @return string
- */
- public static function formatterPrivateKey($priKey)
- {
- $res = "-----BEGIN RSA PRIVATE KEY-----\n" .
- wordwrap($priKey, 64, "\n", true) .
- "\n-----END RSA PRIVATE KEY-----";
- return $res;
- }
- /**
- * 私钥分段解密
- * emptyStr 加密字符串
- */
- public static function decrypt($encryptData){
- $privateKey = openssl_pkey_get_private(self::formatterPrivateKey(self::$key));
- $privateKey or die('密钥不可用');
- $decryptData = '';
- $crypto = '';
- $ed = str_split(base64_decode($encryptData),256);
- foreach ($ed as $chunk) {
- if(openssl_private_decrypt($chunk, $decryptData, $privateKey)){
- $crypto .= $decryptData;
- }else{
- die('解密失败');
- }
- }
- return $crypto;
- }
- /**
- * 公钥加密(分段加密)
- * $originalData 需要加密的字符串
- */
- function encrypt($originalData) {
- // 解析公钥
- $publicKey = openssl_pkey_get_public(self::formatterPublicKey($this->setting['pkey']));
- if ($publicKey === false) {
- die('公钥解析失败');
- }
- $crypto = '';
- foreach (str_split($originalData, 245) as $chunk) {
- $encryptData = '';
- if (!openssl_public_encrypt($chunk, $encryptData, $publicKey)) {
- // 输出 OpenSSL 错误信息
- while ($msg = openssl_error_string()) {
- echo $msg . "\n";
- }
- die('加密失败');
- } else {
- $crypto .= $encryptData;
- }
- }
- return base64_encode($crypto);
- }
- }
- //var_dump(Duqi::FlexibleBanks());
|