基於php的加油卡儲值介面調用代碼執行個體

來源:互聯網
上載者:User
代碼描述:基於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
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.