您好,登錄后才能下訂單哦!
本篇內容介紹了“如何用代碼實現聚合接口對接”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
<?php /** * 聚合接口模型. * * @version TS4.5 * @name JuheModel * * @author Foreach */ class Juhe { public $appkey_config = array( 'tel'=>'appkey', 'flow'=>'appkey', 'sinopec'=>'appkey', ); public $openid = 'JH160141dd01f07b3149d99dad44802431'; public $appkey = ''; /** * juheModel constructor. * @param string $type tel 話費 flow 流量 sinopec 油卡 */ public function __construct($type) { switch($type){ case 'tel': $this ->appkey = $this ->appkey_config['tel']; break; case 'flow': $this ->appkey = $this ->appkey_config['flow']; break; case 'sinopec': $this ->appkey = $this ->appkey_config['sinopec']; break; } } /** * 【油卡】加油卡充值 * @param $proid * @param $cardnum * @param $orderid * @param $game_userid * @param $gasCardTel * @param $gasCardName * @param $chargeType * @return mixed */ public function order($proid,$cardnum,$orderid,$game_userid,$gasCardTel,$gasCardName,$chargeType) { $url = "http://op.juhe.cn/ofpay/sinopec/onlineorder"; $newkey = $this->openid.$this->appkey.$proid.$cardnum.$game_userid.$orderid; $sign= md5($newkey); $params = array( "proid" => $proid,//產品id:10000(中石化50元加油卡)、10001(中石化100元加油卡)、10003(中石化500元加油卡)、10004(中石化1000元加油卡)、10007(中石化任意金額充值)、10008(中石油任意金額充值) "cardnum" => $cardnum,//充值數量 任意充 (整數(元)),其余面值固定值為1 "orderid" => $orderid,//商家訂單號,8-32位字母數字組合 "game_userid" => $game_userid,//加油卡卡號,中石化:以100011開頭的卡號、中石油:以9開頭的卡號 "gasCardTel" => $gasCardTel,//持卡人手機號碼 "gasCardName" => $gasCardName,//持卡人姓名 "chargeType" => $chargeType,//加油卡類型 (1:中石化、2:中石油;默認為1) "key" => $this->appkey,//應用APPKEY(應用詳細頁查詢) "sign" => $sign,//校驗值,md5(OpenID+key+proid+cardnum+game_userid+orderid),OpenID在個人中心查詢 ); $content = $this->juhecurl($url, $params); $result = json_decode($content, true); return $result; } /** * 【油卡】油卡查詢訂單狀態 * @param $orderid * @return mixed */ public function ordersta($orderid) { $url = "http://op.juhe.cn/ofpay/sinopec/ordersta"; $params = array( "orderid" => $orderid,//商家訂單號,8-32位字母數字組合 "key" => $this->appkey,//應用APPKEY(應用詳細頁查詢) ); $content = $this->juhecurl($url, $params); $result = json_decode($content, true); return $result; } /** * 【流量】全部流量套餐列表 * @return mixed */ public function flowlist() { //************1.全部流量套餐列表************ $url = "http://v.juhe.cn/flow/list"; $params = array( "key" => $this->appkey,//應用APPKEY(應用詳細頁查詢) ); $paramstring = http_build_query($params); $content = $this->juhecurl($url,$paramstring); $result = json_decode($content,true); return $result; } /** * 【流量】檢測號碼支付的流量套餐 * @param $phone * @return mixed */ public function telcheck($phone) { //************2.檢測號碼支持的流量套餐************ $url = "http://v.juhe.cn/flow/telcheck"; $params = array( "phone" => $phone,//要查詢的手機號碼 "key" => $this->appkey,//應用APPKEY(應用詳細頁查詢) ); $paramstring = http_build_query($params); $content = $this->juhecurl($url,$paramstring); $result = json_decode($content,true); return $result; //************************************************** } /** * 【流量】檢測號碼購買的流量是否存在 * @param $phone * @param $price * @return bool */ public function telpricecheck($phone,$price) { //************2.檢測號碼支持的流量套餐************ $url = "http://v.juhe.cn/flow/telcheck"; $params = array( "phone" => $phone,//要查詢的手機號碼 "key" => $this->appkey,//應用APPKEY(應用詳細頁查詢) ); $paramstring = http_build_query($params); $content = $this->juhecurl($url,$paramstring); $result = json_decode($content,true); if($result){ if($result['error_code']=='0'){ $product=$result['result'][0]; $flows=$result['result'][0]['flows']; if($flows && count($flows)>0) { foreach ($flows as $flow) { if($flow['p']==$price) { $product['item']=$flow; return $product; } } } return false; }else{ return false; } }else{ return false; } //************************************************** } /** * 【流量】提交流量充值 * @param $phone * @param $pid * @param $orderid * @return mixed */ public function recharge($phone,$pid,$orderid) { //************3.提交流量充值************ $newkey = $this->openid.$this->appkey.$phone.$pid.$orderid; $sign= md5($newkey); $url = "http://v.juhe.cn/flow/recharge"; $params = array( "phone" => $phone,//需要充值流量的手機號碼 "pid" => $pid,//流量套餐ID "orderid" => $orderid,//自定義訂單號,8-32字母數字組合 "key" => $this->appkey,//應用APPKEY(應用詳細頁查詢) "sign" => $sign,//校驗值,md5(<b>OpenID</b>+key+phone+pid+orderid),結果轉為小寫 ); $paramstring = http_build_query($params); $content = $this->juhecurl($url,$paramstring); $result = json_decode($content,true); return $result; //************************************************** } /** * 【流量】訂單狀態查詢 * @param $orderid * @return mixed */ public function orderstaflow($orderid) { //************4.訂單狀態查詢************ $url = "http://v.juhe.cn/flow/ordersta"; $params = array( "orderid" => $orderid,//商家訂單號,8-32位字母數字組合,由您自己生成 "key" => $this ->appkey, //應用APPKEY(應用詳細頁查詢) ); $paramstring = http_build_query($params); $content = $this->juhecurl($url,$paramstring); $result = json_decode($content,true); return $result; //************************************************** } /** * 【話費】檢測手機號是否能充值 * @param $phone * @param $cardnum * @return mixed */ public function telcheckmobile($phone,$cardnum) { //************1.檢測手機號碼是否能充值************ $url = "http://op.juhe.cn/ofpay/mobile/telcheck"; $params = array( "phoneno" => $phone,//要查詢的手機號碼 "cardnum" => $cardnum,//充值金額,目前可選:10、20、30、50、100、300 "key" => $this ->appkey //應用APPKEY(應用詳細頁查詢) ); $paramstring = http_build_query($params); $content = $this->juhecurl($url,$paramstring); $result = json_decode($content,true); return $result; //************************************************** } /** * 【話費】根據手機號和面值查詢商品 * @param $phone * @param $cardnum * @return mixed */ public function telquery($phone,$cardnum) { //************2.根據手機號和面值查詢商品************ $url = "http://op.juhe.cn/ofpay/mobile/telquery"; $params = array( "phoneno" => $phone,//要查詢的手機號碼 "cardnum" => $cardnum,//充值金額,目前可選:10、20、30、50、100、300 "key" => $this ->appkey //應用APPKEY(應用詳細頁查詢) ); $paramstring = http_build_query($params); $content = $this->juhecurl($url,$paramstring); $result = json_decode($content,true); return $result; //************************************************** } /** * 【話費】手機直充接口 * @param $phone * @param $cardnum * @param $orderid * @return mixed */ public function onlineorder($phone,$cardnum,$orderid) { //************3.手機直充接口************ $url = "http://op.juhe.cn/ofpay/mobile/onlineorder"; $newkey = $this->openid.$this->appkey.$phone.$cardnum.$orderid; $sign= md5($newkey); $params = array( "phoneno" => $phone,//要查詢的手機號碼 "cardnum" => $cardnum,//充值金額,目前可選:10、20、30、50、100、300 "orderid" => $orderid,//商家訂單號,8-32位字母數字組合,由您自己生成 "key" => $this ->appkey, //應用APPKEY(應用詳細頁查詢) "sign" => $sign //校驗值,md5(OpenID+key+phoneno+cardnum+orderid),OpenID在個人中心查詢 ); $paramstring = http_build_query($params); $content = $this->juhecurl($url,$paramstring); $result = json_decode($content,true); return $result; //************************************************** } /** * 【話費】訂單狀態查詢 * @param $orderid * @return mixed */ public function orderstamobile($orderid) { //************4.訂單狀態查詢************ $url = "http://op.juhe.cn/ofpay/mobile/ordersta"; $params = array( "orderid" => $orderid,//商家訂單號,8-32位字母數字組合,由您自己生成 "key" => $this ->appkey, //應用APPKEY(應用詳細頁查詢) ); $paramstring = http_build_query($params); $content = $this->juhecurl($url,$paramstring); $result = json_decode($content,true); return $result; //************************************************** } /** * 【公共】請求接口返回內容 * @param string $url [請求的URL地址] * @param string $params [請求的參數] * @param int $ispost [是否采用POST形式] * @return string */ function juhecurl($url,$params='',$ispost=0){ $params = htmlspecialchars_decode($params); $httpInfo = array(); $ch = curl_init(); curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 ); curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' ); curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 3600 ); curl_setopt( $ch, CURLOPT_TIMEOUT , 3600); curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true ); curl_setopt( $ch, CURLOPT_FOLLOWLOCATION , true); if( $ispost ) { curl_setopt( $ch , CURLOPT_POST , true ); $paramstring = http_build_query($params); curl_setopt( $ch , CURLOPT_POSTFIELDS , $paramstring ); curl_setopt( $ch , CURLOPT_URL , $url ); } else { if($params){ curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params ); }else{ curl_setopt( $ch , CURLOPT_URL , $url); } } $response = curl_exec( $ch ); logInfo($url.'-請求地址','juhe_push','JuheLog'); logInfo(json_encode($params).'-請求數據','juhe_push','JuheLog'); logInfo($response.'-返回數據','juhe_push','JuheLog'); if ($response === FALSE) { return false; } //$httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE ); //$httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) ); curl_close( $ch ); return $response; } }
“如何用代碼實現聚合接口對接”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。