手機直充接口代碼如下請參考代碼注釋進行修改)
classofcard_service{
var$gateway;//手機直充網關地址
var$param;//查詢參數
/**
*從配置文件及入口文件中初始化變量
*@paramstring$cardnum話費面值
*@paramstring$order_id訂單號
*@paramstring$game_userid手機號
*@paramstring$useridSP編碼
*@paramstring$userpwsSP接入密碼
*@paramstring$version歐飛接口版本(固定值為:4.0)
*@todo配置文件數組化
*/
functionofcard_service($cardnum,$order_id,$game_userid,$userid,$userpws,$version){
$this->gateway='http://esales1.ofcard.com:8088/onlineorder.do';
$this->param=array();
$this->param['userid']=$userid;
$this->param['userpws']=md5($userpws);
//$this->param['cardid']='140101';
$this->param['cardid']=$this->get_cardid($game_userid);
$this->param['cardnum']=$cardnum/50;
$this->param['sporder_id']=$order_id;
$this->param['sporder_time']=date('YmdHis');
$this->param['game_userid']=$game_userid;
$keystr='OFCARD';
$this->param['md5_str']=strtoupper(md5(
$this->param['userid'].
$this->param['userpws'].
$this->param['cardid'].
$this->param['cardnum'].
$this->param['sporder_id'].
$this->param['sporder_time'].
$game_userid.$keystr));
$this->param['version']=$version;
}
/**
*進行充值,使用snoopy提交
*@paramSnoopy$snoopy
*@paramezSQL_mysql$db
*@paramstring$order_id
*@return充值結果
*@todosnoopy集成
*/
functionrecharge($snoopy,$db,$order_id){
$snoopy->submit($this->gateway,$this->param);
//下面數據庫操作屬于商家邏輯
$sql="UPDATE`recharge`SET`is_recharge`=".$this->get_xml_value("game_state",$snoopy->results).",`ofcard_trade_id`='".
$this->get_xml_value("orderid",$snoopy->results)."',`purchase_price`='".
$this->get_xml_value("ordercash",$snoopy->results).
"'WHERE`order_id`=".$order_id;
$db->query($sql);
return$this->get_xml_value("game_state",$snoopy->results);
}
/**
*xml數據簡單解析
*@paramstring$name
*@paramstring$xml
*@returnstring$ret
*/
functionget_xml_value($name,$xml)
{
$ret='';
preg_match("|<".$name.">(.*)</".$name.">|U",$xml,$ret);
return$ret[1];
}
/**
*
*獲取充值狀態
*http://202.102.53.141:83/api/que...x&spbillid=spxxxxxx
*@paramstring$useridSP編碼
*@paramstring$spbillid商戶系統訂單號
*@return充值狀態
*/
functionget_is_recharge($userid,$spbillid){
$status_url="http://202.102.53.141:83/api/query.do?userid=".$userid."&spbillid=".$spbillid;
returnfile_get_contents($status_url);
}
/**
*
*獲取賬戶余額
*@paramstring$userid
*@paramstring$userpws
*@paramstring$version
*@return賬戶余額
*/
functionget_leftcredit($userid,$userpws,$version)
{
$url="http://esales1.ofcard.com:8088/queryuserinfo.do?userid=".$userid."&userpws=".md5($userpws)."&version=".$version;
returnself::get_xml_value("ret_leftcredit",file_get_contents($url));
}
/**
*是否可以充值(未進行余額判斷)
*@paramstring$phoneno
*@paramstring$price
*@paramstring$userid
*@returnbool是否可以充值
*/
functionis_recharge($phoneno,$price,$userid){
$url="http://esales1.ofcard.com:8088/telcheck.do?phoneno=".$phoneno."&price=".$price."&userid=".$userid;
$ret=split('#',file_get_contents($url));
return(1==$ret[0]);
}
/**
*
*所需提貨商品的編碼
*(現全國移動聯通快充直充編碼為且僅為140101,電信手機編碼為且僅為18)
*@paramstring$phoneno手機號碼
*@todo常量加入配置文件
*/
functionget_cardid($phoneno){
$num=substr($phoneno,0,3);
$ChinaMobile=array(134,135,147,147,136,137,138,139,150,151,152,182,157,158,159,187,188);
$ChinaUnicom=array(130,131,132,155,156,145,185,186);
$ChinaTelecom=array(133,153,180,189);
if(in_array($num,$ChinaMobile)||in_array($num,$ChinaUnicom)){
return'140101';
}
if(in_array($num,$ChinaTelecom)){
return'18';
}
}
}
手機直充接口使用如下:
$ofcard=newofcard_service($original_price,$dingdan,$mobile,$userid,$userpws,$version);
$ofcard->recharge($snoopy,$db,$dingdan);
新聞熱點
疑難解答