程式碼描述:基於php的加油卡充值介面呼叫程式碼實例 關聯資料:加油卡儲值 介面位址:http://www.juhe.cn/docs/api/id/87
-
// ------------------------------ ------------------------------------------
- // | JuhePHP [ NO ZUO NO DIE ]
- // ------------------------------------------ ----------------------------
- // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
- // ------------------------------------------- ---------------------------
- // | Author: Juhedata
- // -- -------------------------------------------------- ------------------
-
- //------------------------ ----------
- // 加油卡儲值呼叫範例程式碼- 聚合資料
- // 線上介面文件:http://www.juhe.cn/docs/87
- / /----------------------------------
-
- header('Content-type:text/ html;charset=utf-8');
-
-
- //設定您申請的appkey
- $appkey = "***************** ****";
-
-
-
-
- //************1.訂單狀態查詢********** **
- $url = "http://op.juhe.cn/ofpay/sinopec/ordersta";
- $params = array(
- "orderid" => "",//商家訂單編號,8-32位元字母數字組合
- "key" => $appkey,//應用APPKEY(應用詳細頁查詢)
- );
- $paramstring = http_build_query($params);
- $ content = juhecurl($url,$paramstring);
- $result = json_decode($content,true);
- if($result){
- if($result['error_code']=='0 '){
- print_r($result);
- }else{
- echo $result['error_code'].":".$result['reason'];
- }
- } else{
- echo "請求失敗";
- }
- //****************************** ********************
-
-
-
-
- //************2 .帳戶餘額查詢************
- $url = "http://op.juhe.cn/ofpay/sinopec/yue";
- $params = array(
- "timestamp" => "",//當前時間戳,如:1432788379
- "key" => $appkey,//應用APPKEY(應用詳細頁查詢)
- "sign" => "", //校驗值,md5(OpenID key timestamp),OpenID在個人中心查詢
- );
- $paramstring = http_build_query($params);
- $content = juhecurl($url,$paramstring);
- $result = json_decode($content,true);
- if($result){
- if($result['error_code']=='0'){
- print_r($result) ;
- }else{
- echo $result['error_code'].":".$result['reason'];
- }
- }else{
- echo "請求失敗";
- }
- //***************************************** *********
-
-
-
-
- //************3.加油卡儲值******* *****
- $url = "http://op.juhe.cn/ofpay/sinopec/onlineorder";
- $params = array(
- "proid" => "",//產品id:10000(中石化50元加油卡)、10001(中石化100元加油卡)、10003(中石化500元加油卡)、10004(中石化1000元加油卡)、10007(中石化任意金額充值)、10008(任意金額充值)
- "cardnum" => "",//充值數量任意充(整數(元)),其餘面值固定值為1
- "orderid" => "",//商家訂單號,8-32位元字母數字組合
- "game_userid" => "",//加油卡號,中石化:以100011開頭的卡號、中石油:以9開頭的卡號
- "gasCardTel" => "" ,//持卡人手機號碼
- "gasCardName" => "",//持卡人姓名
- "chargeType" => "",//加油卡類型(1:中石化、2:中石油;預設為1)
- "key" => $appkey,//應用APPKEY(應用詳細頁查詢)
- "sign" => "",//校驗值,md5(OpenID key proid cardnum game_userid orderid ),OpenID在個人中心查詢
- );
- $paramstring = http_build_query($params);
- $content = juhecurl($url,$paramstring);
- $result = json_decode($content, true);
- if($result){
- if($result['error_code']=='0'){
- print_r($result);
- }else{
- echo $result['error_code'].":".$result['reason'];
- }
- }else{
- echo "請求失敗";
- }
- //**************************************************
-
-
-
-
-
- /**
- * 請求介面回傳內容
- * @param string $url [請求的URL位址]
- * @param string $ params [要求的參數]
- * @param int $ipost [是否採用POST形式]
- * @return string
- */
- function juhecurl($url,$params=false,$ispost=0){
- $httpInfo = array();
- $ch = curl_init( );
-
- curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
- curl_setopt( $ch, CURLOPT_USERAGENT , '], ); );
- 捲曲_設定選項( $ch, CURLOPT_TIMEOUT , 60);
- curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
- curl_setopt($ch, CURLOPT_FOLLOW );
- curl_setopt($ch, CURLOPT_FOLLOWLOCLO);
- curl_setopt( $ch , CURLOPT_POST , true );
- curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
- curl_setopt( $ch , CURLOPT_URL 🎜> {
- if($params){
- curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
- }else{
- curl_setopt( $URch , CURPT_ $URch , CURPT_ $UR網址);
- }
- }
- $response = curl_exec( $ch );
- if ($response === FALSE) {
- //echo "cURL Error: " . curl_error($ch);
- return false;
- }
- $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
- $httpInfo = array_merge( $httpInfo , curl_ info(> $httpInfo = array_merge( $httpInfo , curl_info); >curl_close( $ch );
- return $response;
- }
-
-
- 複製程式碼
-
-
卡充值, php
|