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

Fuel card recharge interface calling code example based on PHP

Jul 25, 2016 am 08:46 AM

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 of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1269
29
C# Tutorial
1248
24
PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

How does PHP type hinting work, including scalar types, return types, union types, and nullable types? How does PHP type hinting work, including scalar types, return types, union types, and nullable types? Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

See all articles