PHP-based fuel card recharge interface Call Code instance

Source: Internet
Author: User
Tags openid
Code Description: PHP-based fuel card recharge interface Call Code instance
Related data: Refueling card Recharge
Interface Address: http://www.juhe.cn/docs/api/id/87
  1. // +----------------------------------------------------------------------
  2. // | juhephp [No ZUO no Die]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
  5. // +----------------------------------------------------------------------
  6. // | Author:juhedata
  7. // +----------------------------------------------------------------------
  8. //----------------------------------
  9. Refueling Card Recharge Call sample code-aggregate data
  10. Online interface Documentation: HTTP://WWW.JUHE.CN/DOCS/87
  11. //----------------------------------
  12. Header (' Content-type:text/html;charset=utf-8 ');
  13. Configure the Appkey you requested
  14. $appkey = "*********************";
  15. 1. Order Status Inquiry ************
  16. $url = "Http://op.juhe.cn/ofpay/sinopec/ordersta";
  17. $params = Array (
  18. "OrderID" and ","//Merchant order number, 8-32-digit alphanumeric combination
  19. "Key" = $appkey,//Application Appkey (Application Detail page query)
  20. );
  21. $paramstring = Http_build_query ($params);
  22. $content = Juhecurl ($url, $paramstring);
  23. $result = Json_decode ($content, true);
  24. if ($result) {
  25. if ($result [' error_code ']== ' 0 ') {
  26. Print_r ($result);
  27. }else{
  28. echo $result [' Error_code ']. ":". $result [' reason '];
  29. }
  30. }else{
  31. echo "Request Failed";
  32. }
  33. //**************************************************
  34. 2. Account Balance Enquiry ************
  35. $url = "Http://op.juhe.cn/ofpay/sinopec/yue";
  36. $params = Array (
  37. "Timestamp" = "" ",//current timestamp, e.g.: 1432788379
  38. "Key" = $appkey,//Application Appkey (Application Detail page query)
  39. "Sign" = "" ",//checksum value, MD5 (OPENID+KEY+TIMESTAMP), OpenID in the Personal center query
  40. );
  41. $paramstring = Http_build_query ($params);
  42. $content = Juhecurl ($url, $paramstring);
  43. $result = Json_decode ($content, true);
  44. if ($result) {
  45. if ($result [' error_code ']== ' 0 ') {
  46. Print_r ($result);
  47. }else{
  48. echo $result [' Error_code ']. ":". $result [' reason '];
  49. }
  50. }else{
  51. echo "Request Failed";
  52. }
  53. //**************************************************
  54. 3. Refueling Card Recharge ************
  55. $url = "Http://op.juhe.cn/ofpay/sinopec/onlineorder";
  56. $params = Array (
  57. "Proid" and "" ",//Product id:10000 (Sinopec 50 Yuan Refueling card), 10001 (Sinopec 100 Yuan Refueling card), 10003 (Sinopec 500 Yuan Refueling card), 10004 (Sinopec 1000 Yuan Refueling card), 10007 (Sinopec any amount of recharge) , 10008 (any amount of PetroChina)
  58. "Cardnum" and "" ",//recharge the amount of any charge (integer (yuan)), the remaining face value is fixed at 1
  59. "OrderID" and ","//Merchant order number, 8-32-digit alphanumeric combination
  60. "Game_userid" and "" ",//refueling card number, Sinopec: Starting with 100011 card number, PetroChina: 9 card number
  61. "Gascardtel" and "" ",//Cardholder's mobile number
  62. "Gascardname" and "" ",//Cardholder's name
  63. "Chargetype" and "" ",//Fuel card type (1: Sinopec, 2: PetroChina; default = 1)
  64. "Key" = $appkey,//Application Appkey (Application Detail page query)
  65. "Sign" = "" ",//checksum value, MD5 (Openid+key+proid+cardnum+game_userid+orderid), OpenID in the Personal center query
  66. );
  67. $paramstring = Http_build_query ($params);
  68. $content = Juhecurl ($url, $paramstring);
  69. $result = Json_decode ($content, true);
  70. if ($result) {
  71. if ($result [' error_code ']== ' 0 ') {
  72. Print_r ($result);
  73. }else{
  74. echo $result [' Error_code ']. ":". $result [' reason '];
  75. }
  76. }else{
  77. echo "Request Failed";
  78. }
  79. //**************************************************
  80. /**
  81. * Request interface to return content
  82. * @param string $url [requested URL address]
  83. * @param string $params [parameter requested]
  84. * @param int $ipost [if post is used]
  85. * @return String
  86. */
  87. function Juhecurl ($url, $params =false, $ispost =0) {
  88. $httpInfo = Array ();
  89. $ch = Curl_init ();
  90. curl_setopt ($ch, curlopt_http_version, curl_http_version_1_1);
  91. curl_setopt ($ch, curlopt_useragent, ' juhedata ');
  92. curl_setopt ($ch, curlopt_connecttimeout, 60);
  93. curl_setopt ($ch, curlopt_timeout, 60);
  94. curl_setopt ($ch, Curlopt_returntransfer, true);
  95. curl_setopt ($ch, curlopt_followlocation, true);
  96. if ($ispost)
  97. {
  98. curl_setopt ($ch, Curlopt_post, true);
  99. curl_setopt ($ch, Curlopt_postfields, $params);
  100. curl_setopt ($ch, Curlopt_url, $url);
  101. }
  102. Else
  103. {
  104. if ($params) {
  105. curl_setopt ($ch, Curlopt_url, $url. '? '. $params);
  106. }else{
  107. curl_setopt ($ch, Curlopt_url, $url);
  108. }
  109. }
  110. $response = curl_exec ($ch);
  111. if ($response = = = FALSE) {
  112. echo "CURL Error:". Curl_error ($ch);
  113. return false;
  114. }
  115. $httpCode = Curl_getinfo ($ch, Curlinfo_http_code);
  116. $httpInfo = Array_merge ($httpInfo, Curl_getinfo ($ch));
  117. Curl_close ($ch);
  118. return $response;
  119. }
Copy Code
Card Recharge, PHP
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.