Recharge.class.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace Common\Ext;
  3. class Recharge
  4. {
  5. private $appkey;
  6. private $openid;
  7. private $telCheckUrl = 'http://op.juhe.cn/ofpay/mobile/telcheck';
  8. private $telQueryUrl = 'http://op.juhe.cn/ofpay/mobile/telquery';
  9. private $submitUrl = 'http://op.juhe.cn/ofpay/mobile/onlineorder';
  10. private $staUrl = 'http://op.juhe.cn/ofpay/mobile/ordersta';
  11. public function __construct($appkey, $openid)
  12. {
  13. $this->appkey = $appkey;
  14. $this->openid = $openid;
  15. }
  16. public function telcheck($mobile, $pervalue)
  17. {
  18. $params = 'key=' . $this->appkey . '&phoneno=' . $mobile . '&cardnum=' . $pervalue;
  19. $content = $this->juhecurl($this->telCheckUrl, $params);
  20. $result = $this->_returnArray($content);
  21. if ($result['error_code'] == '0') {
  22. return true;
  23. }
  24. else {
  25. return false;
  26. }
  27. }
  28. public function telquery($mobile, $pervalue)
  29. {
  30. $params = 'key=' . $this->appkey . '&phoneno=' . $mobile . '&cardnum=' . $pervalue;
  31. $content = $this->juhecurl($this->telQueryUrl, $params);
  32. return $this->_returnArray($content);
  33. }
  34. public function telcz($mobile, $pervalue, $orderid)
  35. {
  36. $sign = md5($this->openid . $this->appkey . $mobile . $pervalue . $orderid);
  37. $params = array('key' => $this->appkey, 'phoneno' => $mobile, 'cardnum' => $pervalue, 'orderid' => $orderid, 'sign' => $sign);
  38. $content = $this->juhecurl($this->submitUrl, $params, 1);
  39. return $this->_returnArray($content);
  40. }
  41. public function sta($orderid)
  42. {
  43. $params = 'key=' . $this->appkey . '&orderid=' . $orderid;
  44. $content = $this->juhecurl($this->staUrl, $params);
  45. return $this->_returnArray($content);
  46. }
  47. public function _returnArray($content)
  48. {
  49. return json_decode($content, true);
  50. }
  51. public function juhecurl($url, $params = false, $ispost = 0)
  52. {
  53. $httpInfo = array();
  54. $ch = curl_init();
  55. curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
  56. curl_setopt($ch, CURLOPT_USERAGENT, 'JuheData');
  57. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 60);
  58. curl_setopt($ch, CURLOPT_TIMEOUT, 60);
  59. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  60. if ($ispost) {
  61. curl_setopt($ch, CURLOPT_POST, true);
  62. curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
  63. curl_setopt($ch, CURLOPT_URL, $url);
  64. }
  65. else if ($params) {
  66. curl_setopt($ch, CURLOPT_URL, $url . '?' . $params);
  67. }
  68. else {
  69. curl_setopt($ch, CURLOPT_URL, $url);
  70. }
  71. $response = curl_exec($ch);
  72. if ($response === false) {
  73. return false;
  74. }
  75. $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  76. $httpInfo = array_merge($httpInfo, curl_getinfo($ch));
  77. curl_close($ch);
  78. return $response;
  79. }
  80. }
  81. ?>