Home  >  Article  >  Backend Development  >  Fuel card recharge interface calling code example based on PHP

Fuel card recharge interface calling code example based on PHP

WBOY
WBOYOriginal
2016-07-25 08:46:001124browse
Code description: PHP-based gas card recharge interface calling code example
Associated data: Gas 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. // Gas card recharge call sample code- Aggregated 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 for
  14. $appkey = "***** ****************";
  15. //************1. Order status query************ ****
  16. $url = "http://op.juhe.cn/ofpay/sinopec/ordersta";
  17. $params = array(
  18. "orderid" => "",//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 inquiry************
  35. $url = "http://op.juhe.cn/ofpay/sinopec/yue";
  36. $params = array(
  37. "timestamp" => "",//Current timestamp, such as: 1432788379
  38. "key" => $appkey,//Application APPKEY (application detail page query)
  39. "sign" => "" ,//Check value, md5 (OpenID+key+timestamp), OpenID is queried in the 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. Gas card recharge************
  55. $url = "http://op.juhe.cn/ofpay/sinopec/onlineorder";
  56. $params = array(
  57. " proid" => "",//Product id: 10000 (Sinopec 50 yuan gas card), 10001 (Sinopec 100 yuan gas card), 10003 (Sinopec 500 yuan gas card), 10004 (Sinopec 1,000 yuan gas card), 10007 (Recharge any amount of Sinopec), 10008 (Recharge any amount of PetroChina)
  58. "cardnum" => "", //Recharge any amount (integer (yuan)), the remaining face values ​​are fixed at 1
  59. "orderid" => "",//Merchant order number, 8-32 digit alphanumeric combination
  60. "game_userid" => "",//Gas card number, Sinopec: card number starting with 100011, PetroChina: card number starting with 9
  61. "gasCardTel " => "",//Cardholder's mobile phone number
  62. "gasCardName" => "",//Cardholder's name
  63. "chargeType" => "",//Gas card type (1: Sinopec, 2: PetroChina; the default is 1)
  64. "key" => $appkey,//Application APPKEY (application details page query)
  65. "sign" => "",//check value, md5 (OpenID+key+ proid+cardnum+game_userid+orderid), OpenID is queried 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 address]
  83. * @param string $params [Requested parameters]
  84. * @param int $ipost [Whether to use 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. }
复制代码
卡充值, php


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php cast type conversionNext article:php cast type conversion