LgApi.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. <?php
  2. namespace app\utils;
  3. /**
  4. *
  5. * Created by PhpStorm.
  6. * User: admin
  7. * Date: 2017/8/18
  8. * Time: 17:50
  9. */
  10. class LgApi
  11. {
  12. public $apiUrl;
  13. public $method;
  14. public $setting;
  15. public $store_id;
  16. public static $key;
  17. /**
  18. * 配置信息
  19. * @param $host
  20. * @param $port
  21. */
  22. public function __construct($store_id = 1)
  23. {
  24. $this->store_id = $store_id;
  25. $store_info = \app\models\Store::find()->where(['id'=>$this->store_id])->one();
  26. if ($store_info){
  27. $setting = [
  28. 'version'=>'1.0',
  29. 'mchid'=>$store_info['lg_mch_id'],//mchid
  30. 'projectCode'=>$store_info['lg_project_code'],//ProjectCode
  31. 'parkcode'=>$store_info['lg_park_code'],//parkcode
  32. 'pkey'=>$store_info['lg_pkey'],//公钥
  33. 'key'=>$store_info['lg_key'],//私钥
  34. ];
  35. self::$key = $store_info['lg_key'];
  36. }else{
  37. $setting = [
  38. 'version'=>'1.0',
  39. 'mchid'=>'1836965269132984320',//mchid
  40. 'ProjectCode'=>'1836966182916636673',//ProjectCode
  41. 'parkcode'=>'1744896567810359296',//parkcode
  42. 'pkey'=>'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEApwAXBcCJq4W/iPq8wAp0N9tpEsMQ0kh+BFuMXoOiNEpHaXB9/CfR+5aPr+w1lRsjvQwY5noMdeXs58u8w1nqdazLMlquMP1tPfh9XVit46b4VPJT/dGsjOQAOkgFrgejo3IGyDGzDeBh4QWqJGz2HzNp3E+wLIoe+lMNKbxaO0XYiJBp6Gbu+pIIdsTDxiKhYINOaCjgWx9ebeLmhmIy5+i2jGlKeq4Nn+9EDnSXjhoem5nYOJFpwW8wutJk8dG9RetEHPQ6emnfV2RyAqSA9LndUx66QTegqSMKbU+j5HSREFIIjEUGsxsqEVjeyfnjL5t/RmPfTMWNUlw24nquLQIDAQAB',//平台公钥
  43. 'key'=>'MIIEpAIBAAKCAQEAyIH6QWzz0ZwBUqM7GVeL4kBZkedcV7NRZZtABtm157q5omSQAKMbJjVe65G1Cy0igP5A9Ax8Cg7kWlGgR/AkL/UZJmDiUx+uyumGVyEINS+/irtVSo0vdsXhLYQyrnOqCleX3Pnf8JZvSDLBY8E3TY7fyFNnx53YDpMIaKRyyrPdSIDHjfxWxSsC9CYWtsRrCW9BeBVKaYvHFw1seYnZOrCdA076g0w7I6BB+GOU37gThoBQSAK/D2pHjQ5Vnz1gQYgzSdqCCG8+jlvsS18Rms06U/UlIZ5y8b97J6SdN0NQcLncAB971PPae+KCI3DYdmhey8NFH8vJYEq5p2qVTQIDAQABAoIBADHYokLGl7yp2GhXXRdZPNTT45CSoFHLKfalCF9Lm13O/VxCPMxzwAmZJg5RLF1pbJT94F7rhaCogBt2BG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Xhkz2RE7SwQVg4C0D9NrJeL+q23wA0fBylrtHf6MHZe/UifOw==',//商户私钥
  44. ];
  45. }
  46. $this->setting = $setting;
  47. }
  48. /**
  49. * author xiaohuihui <xzh_tx@163.com>
  50. * @param $url 请求的url
  51. * @param $option 发送的字段
  52. * @param int|array $header 发送的头信息
  53. * @param string $type 请求方法,默认post
  54. * @return mixed | array
  55. */
  56. public static function RequestCurlPay($url, $options=null, $header = [], $type = 'GET') {
  57. $curl = curl_init (); // 启动一个CURL会话
  58. curl_setopt_array($curl, array(
  59. CURLOPT_URL => $url,
  60. CURLOPT_RETURNTRANSFER => true,
  61. CURLOPT_SSL_VERIFYPEER => false,
  62. CURLOPT_SSL_VERIFYHOST => false,
  63. CURLOPT_ENCODING => '',
  64. CURLOPT_MAXREDIRS => 10,
  65. CURLOPT_TIMEOUT => 0,
  66. CURLOPT_FOLLOWLOCATION => true,
  67. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  68. CURLOPT_CUSTOMREQUEST => 'POST',
  69. CURLOPT_POSTFIELDS =>$options,
  70. CURLOPT_HTTPHEADER => $header,
  71. ));
  72. $response = curl_exec($curl);
  73. // print_r($response);die;
  74. curl_close($curl);
  75. return $response;
  76. }
  77. public static function doPost($url, $params, $charset){
  78. // dd($url);
  79. // dd($params);
  80. // $api = "https://apipcs3.dccnet.com.cn/api/jft/api/pay/add/h5/traceless/order/V2";
  81. // $curl = new Curl();
  82. // $curl->setOpt(CURLOPT_SSL_VERIFYPEER, false);
  83. // $curl->get($api);
  84. // $res = $curl->response;
  85. // dd($res);
  86. // $res = json_decode($res, true);
  87. $ch = curl_init();
  88. curl_setopt($ch, CURLOPT_URL, $url);
  89. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  90. "content-type: application/json"
  91. ));
  92. curl_setopt($ch, CURLOPT_POST, true);
  93. curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  94. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  95. curl_setopt($ch, CURLOPT_NOSIGNAL, 1);
  96. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS,8000);
  97. curl_setopt($ch, CURLOPT_TIMEOUT_MS, 30000);
  98. curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
  99. curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false);
  100. // 尝试使用这些选项来允许安全的重新协商
  101. // curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
  102. // curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'DEFAULT:@SECLEVEL=1');
  103. // curl_setopt($ch, CURLOPT_SSL_OPTIONS, CURLSSLOPT_ALLOW_BEAST);
  104. // curl_setopt($ch, CURLOPT_VERBOSE, true); // Enable verbose output
  105. // 尝试添加以下选项,确保不使用不安全的遗留重新协商
  106. // curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
  107. $response = curl_exec($ch);
  108. if ($response === false) {
  109. $error = curl_error($ch);
  110. $errno = curl_errno($ch);
  111. print_r($error);die;
  112. //dd("cURL Error: $error, Error Number: $errno");
  113. }
  114. $resinfo = curl_getinfo($ch);
  115. // dd($resinfo);
  116. curl_close($ch);
  117. // dd($response);
  118. if($resinfo["http_code"] != 200){
  119. throw new \Exception("response status code is not valid. status code: ".$resinfo["http_code"]);
  120. }
  121. return $response;
  122. }
  123. /**
  124. * RSA单独签名方法,未做字符串处理,字符串处理见getSignContent()
  125. * @param $data 待签名字符串
  126. * @param $privatekey 商户私钥,根据keyfromfile来判断是读取字符串还是读取文件,false:填写私钥字符串去回车和空格 true:填写私钥文件路径
  127. * @param $signType 签名方式,RSA:SHA1 RSA2:SHA256
  128. * @param $keyfromfile 私钥获取方式,读取字符串还是读文件
  129. * @return string
  130. * @author mengyu.wh
  131. */
  132. public static function alonersaSign($data, $privatekey, $signType = "RSA2", $keyfromfile = false)
  133. {
  134. if (!$keyfromfile) {
  135. $priKey = $privatekey;
  136. $res = "-----BEGIN RSA PRIVATE KEY-----\n" .
  137. wordwrap($priKey, 64, "\n", true) .
  138. "\n-----END RSA PRIVATE KEY-----";
  139. } else {
  140. $priKey = file_get_contents($privatekey);
  141. $res = openssl_get_privatekey($priKey);
  142. }
  143. ($res) or die('您使用的私钥格式错误,请检查RSA私钥配置');
  144. if ("RSA2" == $signType) {
  145. openssl_sign($data, $sign, $res, OPENSSL_ALGO_SHA256);
  146. } else {
  147. openssl_sign($data, $sign, $res);
  148. }
  149. if ($keyfromfile) {
  150. openssl_free_key($res);
  151. }
  152. $sign = base64_encode($sign);
  153. return $sign;
  154. }
  155. public static function verify($data, $sign, $publicKey, $signType = 'RSA')
  156. {
  157. $pubKey = $publicKey;
  158. $res = "-----BEGIN PUBLIC KEY-----\n" .
  159. wordwrap($pubKey, 64, "\n", true) .
  160. "\n-----END PUBLIC KEY-----";
  161. ($res) or die('支付宝RSA公钥错误。请检查公钥文件格式是否正确');
  162. //调用openssl内置方法验签,返回bool值
  163. if ("RSA2" == $signType) {
  164. $result = (bool)openssl_verify($data, base64_decode($sign), $res, OPENSSL_ALGO_SHA256);
  165. } else {
  166. $result = (bool)openssl_verify($data, base64_decode($sign), $res);
  167. }
  168. return $result;
  169. }
  170. //收款人信息进件,信息实名
  171. public function FlexibleRegister($post_data){
  172. $data['name'] = $post_data['name'];//收款人姓名
  173. $data['certCard'] = $post_data['certCard'];//收款人身份证
  174. $data['parkCodes'] = [$this->setting['parkcode']];
  175. $data['contractType'] = $post_data['contractType'];//签约方式 100 快捷签约
  176. $data['accNo'] = $post_data['accNo'];//银行卡号
  177. $data['bankCode'] = $post_data['bankCode'];//收款人银行编码(调用 1006 此接口)(特殊可选)
  178. $data['bankPhone'] = $post_data['bankPhone'];//预留手机号
  179. $idcardFront = saveTempFile($post_data['idcardFront'], 'jpg');
  180. $idcardBack = saveTempFile($post_data['idcardBack'], 'jpg');
  181. $data['idcardFront'] = $this->processImageUrl($idcardFront);//身份证正面
  182. $data['idcardBack'] = $this->processImageUrl($idcardBack);//身份证徽面
  183. $data['extendjson'] = "{}";//扩展参数
  184. $data['alipayAcc'] = "";//根据签约园区是否支持验证必填 支付宝账号
  185. $data['notifyUrl'] = pay_notify_url('lg/apply-notify', $this->store_id);//实名回调地址
  186. // $data['notifyUrl'] = 'http://id1103.com/index.php/lg/apply-notify/1';//实名回调地址
  187. $new_data = array();
  188. $new_data['mchid'] = $this->setting['mchid']??"1587293811556904960";
  189. $new_data['version'] = $this->setting['version']??"1.0";
  190. $new_data['tranCode'] = "1009";
  191. $new_data['timestamp'] = date("Y-m-d H:i:s");
  192. $new_data['nonceStr'] = mb_substr(md5(uniqid()),0,17);
  193. $new_data['signType'] = "RSA2";
  194. $new_data['tradeNo'] = $post_data['order_id']??uniqid();
  195. // var_dump($data);die;
  196. $new_data['bizContent'] = self::encrypt(json_encode($data));
  197. // $new_data2['bizContent'] = self::encrypt(json_encode(array(
  198. // "parkCode" => $this->setting['parkcode'],
  199. // )));
  200. // print_r($new_data);die;
  201. ksort($new_data);
  202. $data_decode = urldecode(http_build_query($new_data));
  203. $sign = self::alonersaSign($data_decode,$this->setting['key']);
  204. $new_data['sign'] = $sign;
  205. // $ss = "http://lgapi.vev.cn:8002/v1/api/flexible/register";
  206. $ss = "https://lgapi.dq.cn/v1/api/flexible/register";
  207. $s = json_encode($new_data);
  208. $ret = self::RequestCurlPay($ss,$s,array(
  209. "content-type: application/json"
  210. ),"POST");
  211. $_ret = json_decode($ret,true);
  212. if ($_ret['code'] != 10000){
  213. return [
  214. 'status'=>999,
  215. 'msg'=>$_ret['subMsg']
  216. ];
  217. }
  218. return json_decode(self::decrypt($_ret['bizContent']),true);
  219. }
  220. private function processImageUrl($imageUrl)
  221. {
  222. // 获取图片内容
  223. $imageContent = file_get_contents($imageUrl);
  224. // 检查文件大小是否小于 1MB
  225. if (strlen($imageContent) <= 1 * 1024 * 1024) {
  226. // 将文件内容转换为 Base64 编码
  227. $base64Encoded = base64_encode($imageContent);
  228. // 对 Base64 编码后的字符串进行 URL 编码
  229. $urlEncoded = urlencode($base64Encoded);
  230. return $urlEncoded;
  231. } else {
  232. // 判断$imageUrl是否为jpg,如果不是就转换为jpg, $imageUrl是一个本地路径
  233. $type = exif_imagetype($imageUrl);
  234. if ($type != IMAGETYPE_JPEG) {
  235. $image = imagecreatefromstring(file_get_contents($imageUrl));
  236. $newImagePath = tempnam(sys_get_temp_dir(), 'img_') . '.jpg';
  237. imagejpeg($image, $newImagePath);
  238. imagedestroy($image);
  239. $imageUrl = $newImagePath;
  240. }
  241. $imageUrl = Image::ImageSize($imageUrl, 1);
  242. return $this->processImageUrl($imageUrl);
  243. }
  244. }
  245. //收款人进件状态查询
  246. public function FlexibleQuery($post_data){
  247. $new_data = array();
  248. $data['certCard'] = $post_data['certCard'];//收款人身份证
  249. $data['parkCode'] = $this->setting['parkcode'];//收款人身份证
  250. $new_data['mchid'] = $this->setting['mchid']??"1587293811556904960";
  251. $new_data['version'] = $this->setting['version']??"1.0";
  252. $new_data['tranCode'] = "1010";
  253. $new_data['timestamp'] = date("Y-m-d H:i:s");
  254. $new_data['nonceStr'] = mb_substr(md5(uniqid()),0,17);
  255. $new_data['signType'] = "RSA2";
  256. $new_data['tradeNo'] = $post_data['order_id']??uniqid();
  257. $new_data['bizContent'] = self::encrypt(json_encode($data));
  258. ksort($new_data);
  259. $data = urldecode(http_build_query($new_data));
  260. $sign = self::alonersaSign($data,$this->setting['key']);
  261. $new_data['sign'] = $sign;
  262. // $ss = "http://lgapi.vev.cn:8002/v1/api/flexible/query";
  263. $ss = "https://lgapi.dq.cn/v1/api/flexible/query";
  264. $s = json_encode($new_data);
  265. $ret = self::RequestCurlPay($ss,$s,array(
  266. "content-type: application/json"
  267. ),"POST");
  268. $_ret = json_decode($ret,true);
  269. if ($_ret['code'] != 10000){
  270. return [
  271. 'status'=>999,
  272. 'msg'=>$_ret['subMsg']
  273. ];
  274. }
  275. return json_decode(self::decrypt($_ret['bizContent']),true);
  276. }
  277. //收款人银行卡号修改
  278. public function FlexibleMkd($post_data){
  279. $new_data = array();
  280. $data['certCard'] = $post_data['certCard'];//收款人身份证
  281. $data['accNo'] = $post_data['accNo'];//银行卡号
  282. $data['bankCode'] = $post_data['bankCode'];//银行编码
  283. $data['bankPhone'] = $post_data['bankPhone'];//预留手机号
  284. $data['alipayAcc'] = $post_data['alipayAcc'];//支付宝账号
  285. $new_data['mchid'] = $this->setting['mchid']??"1587293811556904960";
  286. $new_data['version'] = $this->setting['version']??"1.0";
  287. $new_data['tranCode'] = "1012";
  288. $new_data['timestamp'] = date("Y-m-d H:i:s");
  289. $new_data['nonceStr'] = mb_substr(md5(uniqid()),0,17);
  290. $new_data['signType'] = "RSA2";
  291. $new_data['tradeNo'] = $post_data['order_id']??uniqid();
  292. $new_data['bizContent'] = self::encrypt(json_encode($data));
  293. ksort($new_data);
  294. $data = urldecode(http_build_query($new_data));
  295. $sign = self::alonersaSign($data,$this->setting['key']);
  296. $new_data['sign'] = $sign;
  297. $ss = "https://lgapi.dq.cn/v1/api/flexible/mkd";
  298. $s = json_encode($new_data);
  299. $ret = self::RequestCurlPay($ss,$s,array(
  300. "content-type: application/json"
  301. ),"POST");
  302. $_ret = json_decode($ret,true);
  303. if ($_ret['code'] != 10000){
  304. return [
  305. 'status'=>999,
  306. 'msg'=>$_ret['subMsg']
  307. ];
  308. }
  309. return json_decode(self::decrypt($_ret['bizContent']),true);
  310. }
  311. // private static $key = "MIIEogIBAAKCAQEAnBEaoP5IiH5p1kfbe/9oK6IPKr+dlZQkaKlFy6c3/8ViDA+WFe6wOhDJLC0SaCmHmp+LNR7GniQhDRBWf3v4Fp2YzFAVCpgKTeaBMMwLogF+yp00C1JieJBV5fD6oD4sJEDpK9ksC1CUSftLO9eeH/2do9b6lzM6qHmLXOAKR0Cp+R26eCcEEXSiXCYCrBExlm83SzFGl++OVBHxz+oQhFfSaynPhy+Jr2hzUag655+Z8S2jcT82a/YQS89StOh9kkUL8hrOV0NWI965crA+JlJF/qp2iN2KEQwYTXU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rVEaIKT4aS8AhoXTXUHjAoGAbm7lX7bLmGBkgEeiaSPWYEfSOTNwxpHvZpC3ccJjOujjAGqhljqtSxOvwRS302okSIRkdYH3xoc0gkPwhnC2Srm18tQpc4N8sIL7fBz7lpV5xoJ2Ye7MFejOkliRsWQpM3doy49NnwfJ2EzzpORA9ru2XXs4dNU+nQvkRAVbzDc=";
  312. //
  313. // private static $pkey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAjKvj/70BMI1Y9sHSTTeUF40JYbUT7TRwyzF7puxyIzuRL03zn1aKGOeiDb9t6CEL2VdgZ7yI4jY9FSgknGr6yzilwQLvh+bvgaTFuZdY/os9S2otWnjPL+IQnFpLaIaoEQUZoZ3aV0D4n/gKupFj5GYnnlLnP+K2Wx1pN+XOZ7nEW8TuflaxRtkeJsUsbFjdFYqjBw/kjLWEndGMCn3qbgzreQFRYixNT7BM75hYEB3ZRq8b5T6UcU5Qsd8ssDdf7T7PA0mTzilCHSoIMx6phYhxG3bf/zudmSQR+6MLr2NbE0L/F4opb6EYY3uB9nWK5/uNQqJDnofD5atcBlJ3DwIDAQAB";
  314. //获取收款人银行卡信息
  315. public function FlexibleBanks(){
  316. $pay_data = array();
  317. $pay_data['mchid'] = $this->setting['mchid']??"1587293811556904960";
  318. $pay_data['version'] = $this->setting['version']??"1.0";
  319. $pay_data['tranCode'] = "1006";
  320. $pay_data['timestamp'] = date("Y-m-d H:i:s");
  321. $pay_data['nonceStr'] = mb_substr(md5(uniqid()),0,17);
  322. $pay_data['signType'] = "RSA2";
  323. $pay_data['tradeNo'] = $data['order_id']??uniqid();
  324. $pay_data['bizContent'] = self::encrypt(json_encode(array(
  325. "parkCode" => $this->setting['parkcode'],
  326. )));
  327. ksort($pay_data);
  328. $data = urldecode(http_build_query($pay_data));
  329. $sign = self::alonersaSign($data,$this->setting['key']);
  330. $pay_data['sign'] = $sign;
  331. // $ss = "http://lgapi.vev.cn:8002/v1/api/flexible/banks";
  332. $ss = "https://lgapi.dq.cn/v1/api/flexible/banks";
  333. $s = json_encode($pay_data);
  334. $ret = self::RequestCurlPay($ss,$s,array(
  335. "content-type: application/json"
  336. ),"POST");
  337. $_ret = json_decode($ret,true);
  338. $bizContent = json_decode(self::decrypt($_ret['bizContent']),true);
  339. return $bizContent;
  340. }
  341. //佣金发放
  342. public function FlexiblePay($post_data){
  343. $new_data = array();
  344. $data['outTradeNo'] = $post_data['outTradeNo'];//唯一批次号
  345. $data['projectCode'] = $this->setting['projectCode'];//项目编码【8812】创建时返回
  346. $data['parkCode'] = $this->setting['parkcode'];
  347. $data['currency'] ='CNY';//币种
  348. $data['amt'] = $post_data['accNo'];//发放总金额 单位分
  349. $payDetails = [
  350. [
  351. // 'tranflowCode' => $post_data['tranflowCode'],//交易明细流水号
  352. 'tranflowCode' => date('YmdHis') . sprintf('%07d', 1),
  353. 'channelType' => '1000',//支付类型,1000 -银行 1003 支付宝(需要园区是否支持而确定支付类型)
  354. 'amt' => $post_data['amt'],//发佣金额 单位分
  355. 'name' => $post_data['name'],//收款人姓名
  356. 'certCard' => $post_data['certCard'],//收款人证件号
  357. 'certType' => '1001',//证件类型
  358. 'extendjson' => "{}",//扩展参数
  359. ]
  360. ];
  361. $data['payDetails'] = $payDetails;//发佣明细
  362. $data['notifyUrl'] = pay_notify_url('lg/cash-notify', $this->store_id);//实名回调地址
  363. $data['extendjson'] = "{}";//扩展参数
  364. // print_r($data);die;
  365. debug_log($data);
  366. $new_data['mchid'] = $this->setting['mchid']??"1587293811556904960";
  367. $new_data['version'] = $this->setting['version']??"1.0";
  368. $new_data['tranCode'] = "8008";
  369. $new_data['timestamp'] = date("Y-m-d H:i:s");
  370. $new_data['nonceStr'] = mb_substr(md5(uniqid()),0,17);
  371. $new_data['signType'] = "RSA2";
  372. $new_data['tradeNo'] = $post_data['order_id']??uniqid();
  373. $new_data['bizContent'] = self::encrypt(json_encode($data));
  374. ksort($new_data);
  375. debug_log($new_data);
  376. $data = urldecode(http_build_query($new_data));
  377. $sign = self::alonersaSign($data,$this->setting['key']);
  378. $new_data['sign'] = $sign;
  379. // $ss = "http://lgapi.vev.cn:8002/v1/api/duqee/pay";
  380. $ss = "https://lgapi.dq.cn/v1/api/duqee/pay";
  381. $s = json_encode($new_data);
  382. $ret = self::RequestCurlPay($ss,$s,array(
  383. "content-type: application/json"
  384. ),"POST");
  385. $_ret = json_decode($ret,true);
  386. debug_log($_ret);
  387. if ($_ret['code'] != 10000){
  388. return [
  389. 'status'=>999,
  390. 'msg'=>$_ret['subMsg']
  391. ];
  392. }
  393. return json_decode(self::decrypt($_ret['bizContent']),true);
  394. }
  395. //佣金发放状态查询
  396. public function FlexiblePayQuery($post_data){
  397. $new_data = array();
  398. $data['outTradeNo'] = $post_data['outTradeNo'];//传入批次号
  399. $data['tranflowCode'] = $post_data['tranflowCode'];//交易明细流水号
  400. $data['parkCode'] = $this->setting['parkcode'];
  401. $new_data['mchid'] = $this->setting['mchid']??"1587293811556904960";
  402. $new_data['version'] = $this->setting['version']??"1.0";
  403. $new_data['tranCode'] = "8009";
  404. $new_data['timestamp'] = date("Y-m-d H:i:s");
  405. $new_data['nonceStr'] = mb_substr(md5(uniqid()),0,17);
  406. $new_data['signType'] = "RSA2";
  407. $new_data['tradeNo'] = $post_data['order_id']??uniqid();
  408. $new_data['bizContent'] = self::encrypt(json_encode($data));
  409. ksort($new_data);
  410. $data = urldecode(http_build_query($new_data));
  411. $sign = self::alonersaSign($data,$this->setting['key']);
  412. $new_data['sign'] = $sign;
  413. // $ss = "http://lgapi.vev.cn:8002/v1/api/duqee/pay/query";
  414. $ss = "https://lgapi.dq.cn/v1/api/duqee/pay/query";
  415. $s = json_encode($new_data);
  416. $ret = self::RequestCurlPay($ss,$s,array(
  417. "content-type: application/json"
  418. ),"POST");
  419. $_ret = json_decode($ret,true);
  420. if ($_ret['code'] != 10000){
  421. return [
  422. 'status'=>999,
  423. 'msg'=>$_ret['subMsg']
  424. ];
  425. }
  426. return json_decode(self::decrypt($_ret['bizContent']),true);
  427. }
  428. /**
  429. * 格式化公钥
  430. * @param $publicKey string 公钥
  431. * @return string
  432. */
  433. public static function formatterPublicKey($publicKey)
  434. {
  435. $res = "-----BEGIN PUBLIC KEY-----\n" .
  436. wordwrap($publicKey, 64, "\n", true) .
  437. "\n-----END PUBLIC KEY-----";
  438. return $res;
  439. }
  440. /**
  441. * 格式化私钥
  442. * @param $priKey string 私钥
  443. * @return string
  444. */
  445. public static function formatterPrivateKey($priKey)
  446. {
  447. $res = "-----BEGIN RSA PRIVATE KEY-----\n" .
  448. wordwrap($priKey, 64, "\n", true) .
  449. "\n-----END RSA PRIVATE KEY-----";
  450. return $res;
  451. }
  452. /**
  453. * 私钥分段解密
  454. * emptyStr 加密字符串
  455. */
  456. public static function decrypt($encryptData){
  457. $privateKey = openssl_pkey_get_private(self::formatterPrivateKey(self::$key));
  458. $privateKey or die('密钥不可用');
  459. $decryptData = '';
  460. $crypto = '';
  461. $ed = str_split(base64_decode($encryptData),256);
  462. foreach ($ed as $chunk) {
  463. if(openssl_private_decrypt($chunk, $decryptData, $privateKey)){
  464. $crypto .= $decryptData;
  465. }else{
  466. die('解密失败');
  467. }
  468. }
  469. return $crypto;
  470. }
  471. /**
  472. * 公钥加密(分段加密)
  473. * $originalData 需要加密的字符串
  474. */
  475. function encrypt($originalData) {
  476. // 解析公钥
  477. $publicKey = openssl_pkey_get_public(self::formatterPublicKey($this->setting['pkey']));
  478. if ($publicKey === false) {
  479. die('公钥解析失败');
  480. }
  481. $crypto = '';
  482. foreach (str_split($originalData, 245) as $chunk) {
  483. $encryptData = '';
  484. if (!openssl_public_encrypt($chunk, $encryptData, $publicKey)) {
  485. // 输出 OpenSSL 错误信息
  486. while ($msg = openssl_error_string()) {
  487. echo $msg . "\n";
  488. }
  489. die('加密失败');
  490. } else {
  491. $crypto .= $encryptData;
  492. }
  493. }
  494. return base64_encode($crypto);
  495. }
  496. }
  497. //var_dump(Duqi::FlexibleBanks());