llpay_apipost_submit.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: tandunzhao
  5. * Date: 2017/12/27
  6. * Time: 下午8:09
  7. */
  8. namespace App\Libs\lianlianpay;
  9. class llpay_apipost_submit
  10. {
  11. var $llpay_config;
  12. /**
  13. *连连退款网关地址
  14. */
  15. function __construct($llpay_config) {
  16. $this->llpay_config = $llpay_config;
  17. }
  18. function LLpaySubmit($llpay_config) {
  19. $this->__construct($llpay_config);
  20. }
  21. function llpay_apipost_submit($llpay_config) {
  22. $this->__construct($llpay_config);
  23. }
  24. /**
  25. * 生成签名结果
  26. * @param $para_sort 已排序要签名的数组
  27. * @return 签名结果字符串
  28. */
  29. function buildRequestMysign($para_sort) {
  30. //把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
  31. $prestr = llpay_core::createLinkstring($para_sort);
  32. $mysign = "";
  33. switch (strtoupper(trim($this->llpay_config['sign_type']))) {
  34. case "MD5" :
  35. $mysign = llpay_md5::md5Sign($prestr, $this->llpay_config['key']);
  36. break;
  37. case "RSA" :
  38. $mysign = llpay_rsa::RsaSign($prestr, $this->llpay_config['RSA_PRIVATE_KEY']);
  39. break;
  40. default :
  41. $mysign = "";
  42. }
  43. // file_put_contents("log.txt",date('Y-m-d H:i:s')."签名:".$mysign."\n", FILE_APPEND);
  44. return $mysign;
  45. }
  46. /**
  47. * 生成要请求给连连支付的参数数组
  48. * @param $para_temp 请求前的参数数组
  49. * @return 要请求的参数数组
  50. */
  51. function buildRequestPara($para_temp) {
  52. //除去待签名参数数组中的空值和签名参数
  53. $para_filter = llpay_core::paraFilter($para_temp);
  54. //对待签名参数数组排序
  55. $para_sort = llpay_core::argSort($para_filter);
  56. //生成签名结果
  57. $mysign = $this->buildRequestMysign($para_sort);
  58. //签名结果与签名方式加入请求提交参数组中
  59. $para_sort['sign'] = $mysign;
  60. $para_sort['sign_type'] = strtoupper(trim($this->llpay_config['sign_type']));
  61. foreach ($para_sort as $key => $value) {
  62. $para_sort[$key] = $value;
  63. }
  64. return $para_sort;
  65. //return urldecode(json_encode($para_sort));
  66. }
  67. /**
  68. * 建立请求,以模拟远程HTTP的POST请求方式构造并获取连连支付的处理结果
  69. * @param $request_data
  70. * @param $llpay_payment_url
  71. * @return string 连连支付处理结果
  72. */
  73. function buildRequestJSON($request_data, $llpay_payment_url) {
  74. $sResult = '';
  75. //待请求参数数组字符串
  76. $request_data = $this->buildRequestPara($request_data);
  77. //远程获取数据
  78. $sResult = llpay_core::getHttpResponseJSON($llpay_payment_url, $request_data);
  79. return $sResult;
  80. }
  81. // /**
  82. // * 建立请求,以模拟远程HTTP的POST请求方式构造并获取连连支付的处理结果
  83. // * @param $para_temp 请求参数数组
  84. // * @return 连连支付处理结果
  85. // */
  86. // function buildRequestJSON($para_temp,$llpay_gateway_new) {
  87. // $sResult = '';
  88. // //待请求参数数组字符串
  89. // $request_data = $this->buildRequestPara($para_temp);
  90. // //远程获取数据
  91. // $sResult = getHttpResponseJSON($llpay_gateway_new, $request_data);
  92. // return $sResult;
  93. // }
  94. function http_post($url, $para) {
  95. $ch = curl_init();
  96. curl_setopt($ch, CURLOPT_URL, $url);
  97. curl_setopt($ch, CURLOPT_POST, 1);
  98. curl_setopt($ch, CURLOPT_HEADER, 0 );
  99. curl_setopt($ch, CURLOPT_POSTFIELDS , $para);// post传输数据
  100. curl_setopt($ch, CURLOPT_RETURNTRANSFER , 1);//不直接输出,返回到变量
  101. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  102. $curl_result = curl_exec($ch);
  103. return $curl_result;
  104. }
  105. }