<?php
class Juhe
{
public $appkey_config = array(
'tel'=>'appkey',
'flow'=>'appkey',
'sinopec'=>'appkey',
);
public $openid = 'JH160141dd01f07b3149d99dad44802431';
public $appkey = '';
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;
}
}
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,
"cardnum" => $cardnum,
"orderid" => $orderid,
"game_userid" => $game_userid,
"gasCardTel" => $gasCardTel,
"gasCardName" => $gasCardName,
"chargeType" => $chargeType,
"key" => $this->appkey,
"sign" => $sign,
);
$content = $this->juhecurl($url, $params);
$result = json_decode($content, true);
return $result;
}
public function ordersta($orderid)
{
$url = "http://op.juhe.cn/ofpay/sinopec/ordersta";
$params = array(
"orderid" => $orderid,
"key" => $this->appkey,
);
$content = $this->juhecurl($url, $params);
$result = json_decode($content, true);
return $result;
}
public function flowlist()
{
$url = "http://v.juhe.cn/flow/list";
$params = array(
"key" => $this->appkey,
);
$paramstring = http_build_query($params);
$content = $this->juhecurl($url,$paramstring);
$result = json_decode($content,true);
return $result;
}
public function telcheck($phone)
{
$url = "http://v.juhe.cn/flow/telcheck";
$params = array(
"phone" => $phone,
"key" => $this->appkey,
);
$paramstring = http_build_query($params);
$content = $this->juhecurl($url,$paramstring);
$result = json_decode($content,true);
return $result;
}
public function telpricecheck($phone,$price)
{
$url = "http://v.juhe.cn/flow/telcheck";
$params = array(
"phone" => $phone,
"key" => $this->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;
}
}
public function recharge($phone,$pid,$orderid)
{
$newkey = $this->openid.$this->appkey.$phone.$pid.$orderid;
$sign= md5($newkey);
$url = "http://v.juhe.cn/flow/recharge";
$params = array(
"phone" => $phone,
"pid" => $pid,
"orderid" => $orderid,
"key" => $this->appkey,
"sign" => $sign,
);
$paramstring = http_build_query($params);
$content = $this->juhecurl($url,$paramstring);
$result = json_decode($content,true);
return $result;
}
public function orderstaflow($orderid)
{
$url = "http://v.juhe.cn/flow/ordersta";
$params = array(
"orderid" => $orderid,
"key" => $this ->appkey,
);
$paramstring = http_build_query($params);
$content = $this->juhecurl($url,$paramstring);
$result = json_decode($content,true);
return $result;
}
public function telcheckmobile($phone,$cardnum)
{
$url = "http://op.juhe.cn/ofpay/mobile/telcheck";
$params = array(
"phoneno" => $phone,
"cardnum" => $cardnum,
"key" => $this ->appkey
);
$paramstring = http_build_query($params);
$content = $this->juhecurl($url,$paramstring);
$result = json_decode($content,true);
return $result;
}
public function telquery($phone,$cardnum)
{
$url = "http://op.juhe.cn/ofpay/mobile/telquery";
$params = array(
"phoneno" => $phone,
"cardnum" => $cardnum,
"key" => $this ->appkey
);
$paramstring = http_build_query($params);
$content = $this->juhecurl($url,$paramstring);
$result = json_decode($content,true);
return $result;
}
public function onlineorder($phone,$cardnum,$orderid)
{
$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,
"orderid" => $orderid,
"key" => $this ->appkey,
"sign" => $sign
);
$paramstring = http_build_query($params);
$content = $this->juhecurl($url,$paramstring);
$result = json_decode($content,true);
return $result;
}
public function orderstamobile($orderid)
{
$url = "http://op.juhe.cn/ofpay/mobile/ordersta";
$params = array(
"orderid" => $orderid,
"key" => $this ->appkey,
);
$paramstring = http_build_query($params);
$content = $this->juhecurl($url,$paramstring);
$result = json_decode($content,true);
return $result;
}
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;
}
curl_close( $ch );
return $response;
}
}