conn.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. function getHexGuid($a){
  3. $r='';
  4. while($a){
  5. $r = sprintf("%02X%s",bcmod($a,256),$r);
  6. $a = bcdiv($a,256);
  7. }
  8. return $r;
  9. }
  10. function mima($data,$key) {
  11. $signbb = md5($data.$key);
  12. return $signbb;
  13. }
  14. //更多资源下载 www.lyzwlkj.vip
  15. function exit_notice($message,$errno){
  16. $return=array(
  17. 'errcode'=>intval($errno),
  18. 'info'=>$message,
  19. );
  20. exit(json_encode($return));
  21. }
  22. function send_post($url, $data) {
  23. $options = array(
  24. 'http' => array(
  25. 'method' => 'POST',
  26. 'header' => 'Content-Type: application/x-www-form-urlencoded; charset=utf-8',
  27. 'content' => $data,
  28. 'timeout' => 15 * 60 // 超时时间(单位:s)
  29. )
  30. );
  31. $context = stream_context_create($options);
  32. $result = file_get_contents($url, false, $context);
  33. return $result;
  34. }
  35. function http_post_json($url, $data){
  36. $headers = array(
  37. 'Content-Type: application/x-www-form-urlencoded; charset=utf-8'
  38. );
  39. $ch = curl_init();
  40. curl_setopt($ch, CURLOPT_URL, $url);
  41. curl_setopt($ch, CURLOPT_TIMEOUT, 60);
  42. curl_setopt($ch, CURLOPT_POST, 1);
  43. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  44. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  45. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  46. $rtn = curl_exec($ch);
  47. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  48. curl_close($ch);
  49. return array($rtn, $httpCode);
  50. }
  51. function post_curl($url, $data, $timeout = 5) {
  52. if (!empty($data['reward'])){
  53. $url.="?reward=".$data['reward'];
  54. }
  55. $ch = curl_init();
  56. curl_setopt($ch,CURLOPT_URL,$url);
  57. curl_setopt($ch,CURLOPT_RETURNTRANSFER,true );
  58. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  59. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  60. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  61. curl_setopt($ch, CURLOPT_POST, true);
  62. curl_setopt($ch,CURLOPT_POSTFIELDS,$data);
  63. $result = curl_exec( $ch );
  64. curl_close($ch);
  65. return $result;
  66. }
  67. //GET提交
  68. function get_curl($url, $timeout = 5) {
  69. $ch = curl_init();
  70. curl_setopt($ch,CURLOPT_URL,$url);
  71. curl_setopt($ch,CURLOPT_RETURNTRANSFER,true );
  72. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  73. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  74. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  75. $result = curl_exec( $ch );
  76. curl_close($ch);
  77. return $result;
  78. }