Php-based fuel card recharge interface call code example

Source: Internet
Author: User
Tags openid
Php-based fuel card recharge interface call code example
Code description: php-based oil card recharge interface call code example
Associated Data: fuel 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. // Example code of the recharge call of the fuel card-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 applied
  14. $ Appkey = "*********************";
  15. // ************ 1. query the order status ************
  16. $ Url = "http://op.juhe.cn/ofpay/sinopec/ordersta ";
  17. $ Params = array (
  18. "Orderid" => "", // merchant order number, 8-32-bit combination of letters and numbers
  19. "Key" => $ appkey, // APPKEY of the application (query on the application details page)
  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. query the account balance ************
  35. $ Url = "http://op.juhe.cn/ofpay/sinopec/yue ";
  36. $ Params = array (
  37. "Timestamp" => "", // Current timestamp, for example, 1432788379
  38. "Key" => $ appkey, // APPKEY of the application (query on the application details page)
  39. "Sign" => "", // Check value, md5 (OpenID + key + timestamp), OpenID query in Personal Center
  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. recharge the oil card ************
  55. $ Url = "http://op.juhe.cn/ofpay/sinopec/onlineorder ";
  56. $ Params = array (
  57. "Proid" => "", // product id: 10000 (Sinopec 50 yuan oil card), 10001 (Sinopec 100 yuan oil card), 10003 (Sinopec 500 yuan oil card), 10004 (Sinopec 1000 yuan refueling card), 10007 (Sinopec any amount of recharge), 10008 (PetroChina any amount of recharge)
  58. "Cardnum" => "", // any charge (integer (RMB) for the number of top-up items, and the fixed value for other denominations is 1
  59. "Orderid" => "", // merchant order number, 8-32-bit combination of letters and numbers
  60. "Game_userid" => "", // oil card number, Sinopec: Card number starting with 100011, and PetroChina: Card number starting with 9
  61. "GasCardTel" => "", // the cardholder's mobile phone number
  62. "GasCardName" => "", // cardholder name
  63. "ChargeType" => "", // card type (1: Sinopec, 2: CNPC; default value: 1)
  64. "Key" => $ appkey, // APPKEY of the application (query on the application details page)
  65. "Sign" => "", // Check value, md5 (OpenID + key + proid + cardnum + game_userid + orderid), OpenID query in the Personal Center
  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. * Content returned by the request interface
  82. * @ Param string $ url [requested URL]
  83. * @ Param string $ params [request parameters]
  84. * @ Param int $ ipost [whether to use the POST form]
  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. }

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.