Home  >  Article  >  Backend Development  >  基于php的加油卡充值接口调用代码实例

基于php的加油卡充值接口调用代码实例

WBOY
WBOYOriginal
2016-07-25 08:46:001022browse
代码描述:基于php的加油卡充值接口调用代码实例
关联数据:加油卡充值
接口地址: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. // 加油卡充值调用示例代码 - 聚合数据
  10. // 在线接口文档:http://www.juhe.cn/docs/87
  11. //----------------------------------
  12. header('Content-type:text/html;charset=utf-8');
  13. //配置您申请的appkey
  14. $appkey = "*********************";
  15. //************1.订单状态查询************
  16. $url = "http://op.juhe.cn/ofpay/sinopec/ordersta";
  17. $params = array(
  18. "orderid" => "",//商家订单号,8-32位字母数字组合
  19. "key" => $appkey,//应用APPKEY(应用详细页查询)
  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 "请求失败";
  32. }
  33. //**************************************************
  34. //************2.账户余额查询************
  35. $url = "http://op.juhe.cn/ofpay/sinopec/yue";
  36. $params = array(
  37. "timestamp" => "",//当前时间戳,如:1432788379
  38. "key" => $appkey,//应用APPKEY(应用详细页查询)
  39. "sign" => "",//校验值,md5(OpenID+key+timestamp),OpenID在个人中心查询
  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 "请求失败";
  52. }
  53. //**************************************************
  54. //************3.加油卡充值************
  55. $url = "http://op.juhe.cn/ofpay/sinopec/onlineorder";
  56. $params = array(
  57. "proid" => "",//产品id:10000(中石化50元加油卡)、10001(中石化100元加油卡)、10003(中石化500元加油卡)、10004(中石化1000元加油卡)、10007(中石化任意金额充值)、10008(中石油任意金额充值)
  58. "cardnum" => "",//充值数量 任意充 (整数(元)),其余面值固定值为1
  59. "orderid" => "",//商家订单号,8-32位字母数字组合
  60. "game_userid" => "",//加油卡卡号,中石化:以100011开头的卡号、中石油:以9开头的卡号
  61. "gasCardTel" => "",//持卡人手机号码
  62. "gasCardName" => "",//持卡人姓名
  63. "chargeType" => "",//加油卡类型 (1:中石化、2:中石油;默认为1)
  64. "key" => $appkey,//应用APPKEY(应用详细页查询)
  65. "sign" => "",//校验值,md5(OpenID+key+proid+cardnum+game_userid+orderid),OpenID在个人中心查询
  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 "请求失败";
  78. }
  79. //**************************************************
  80. /**
  81. * 请求接口返回内容
  82. * @param string $url [请求的URL地址]
  83. * @param string $params [请求的参数]
  84. * @param int $ipost [是否采用POST形式]
  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