kjwithdraw.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. namespace kjwithdraw;
  3. class Kjwithdraw
  4. {
  5. /**
  6. * 除去数组中的空值和签名参数
  7. * @param $para 签名参数组
  8. * return 去掉空值与签名参数后的新签名参数组
  9. */
  10. function paraFilters($para) {
  11. $para_filter = array();
  12. foreach ($para as $key => $val) {
  13. if($key == "sign" || $val == "")continue;
  14. else $para_filter[$key] = $para[$key];
  15. }
  16. return $para_filter;
  17. }
  18. /**
  19. * 对数组排序
  20. * @param $para 排序前的数组
  21. * return 排序后的数组
  22. */
  23. function argSorts($para) {
  24. ksort($para);
  25. reset($para);
  26. return $para;
  27. }
  28. /**
  29. * 签名验证-快接支付
  30. * $datas 数据数组
  31. * $key 密钥
  32. */
  33. function sign($datas = array(), $key = ""){
  34. $str = urldecode(http_build_query($this->argSorts($this->paraFilters($datas))));
  35. // print_r($str);exit;
  36. $sign = md5($str."&key=".$key);
  37. return $sign;
  38. }
  39. /**
  40. * 签名验证-快接支付
  41. * $datas 数据数组
  42. * $key 密钥
  43. */
  44. function getdata($url, $param){
  45. $content = '';
  46. $ch = curl_init();
  47. curl_setopt($ch, CURLOPT_URL, $url);
  48. curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
  49. curl_setopt($ch, CURLOPT_HEADER, false);
  50. curl_setopt($ch, CURLOPT_POST, true);
  51. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  52. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  53. curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
  54. curl_setopt($ch, CURLOPT_TIMEOUT,6);
  55. $content = curl_exec($ch);
  56. //如果发现异常,排查下curl错误
  57. //echo "curl错误:".curl_error($ch);
  58. curl_close($ch);
  59. return $content;
  60. }
  61. }