通达OA与携程平台对接--员工开卡

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hai7425/article/details/80839095
<?
//include_once( "inc/auth.inc.php" );
include_once( "inc/conn.php" );
include_once( "inc/utility_all.php" );
include_once( "inc/utility_org.php" );






$HTML_PAGE_TITLE = _("员工开卡");
include_once( "inc/header.inc.php" );
?>


<body bgcolor="#FFFFFF">




<?
//header('Access-Control-Allow-Origin: *');
//header("Content-type:application/json;charset=utf-8");  


$uid=$_REQUEST["uid"];
$byname=$_REQUEST["byname"];


$query="select user_id,byname,user_name,xiechengkahao,xiechengbianhao,mobil_no,email from user where uid='$uid' limit 1";
$cursor=exequery(TD::conn(),$query);
while($row=mysql_fetch_array($cursor)){
$user_id=$row["user_id"];
$byname=$row["byname"];
$user_name=$row["user_name"];
$mobil_no=$row["mobil_no"];
$email=$row["email"];
if($row["xiechengkahao"]!="" or  $row["xiechengbianhao"]!=""){
 Message("操作提示",_("该用户已经开卡成功无需操作!"));
Button_Back();
  
  }
}


$query1="select staff_card_no from hr_staff_info where user_id='$user_id' limit 1";
$cursor1=exequery(TD::conn(),$query1);
while($row1=mysql_fetch_array($cursor1)){
$staff_card_no=$row1["staff_card_no"];
}


function send_post($url,$data) {
    $options = array(
        'http' => array(
            'method' => 'POST',
            'header' => 'Content-type:application/x-www-form-urlencoded; charset:UTF-8',
            'timeout' => 2,
            'content' => http_build_query($data)
        )
    );
 
    $context = stream_context_create($options);
    $result = file_get_contents($url, false, $context);
    return $result;
}
$res = send_post('https://ct.ctrip.com/corpservice/authorize/getticket',
        array(
            'AppKey'=>'obk_appkey',
            'AppSecurity'=>'obk_appsecurity',
            ));
 
$ticket_context = json_decode($res);
if($ticket_context->Success==1){
$Ticket=$ticket_context->Token;
}
 
print_r($ticket_context);


echo "<hr>";




$AuthenticationInfoList=new StdClass();
$Authentication=new StdClass();
$Authentication->EmployeeID=iconv("gb2312","utf-8",$byname);
$Authentication->Name=iconv("gb2312","utf-8",$user_name);
$Authentication->MobilePhone=iconv("gb2312","utf-8",$mobil_no);
$Authentication->IdCardNo=iconv("gb2312","utf-8",$staff_card_no);
$Authentication->Valid="A";
//"RankName"=>iconv("gb2312","utf-8","工程师"),
$Authentication->SubAccountName=iconv("gb2312","utf-8","china_hei_提前审批");
if($email!=""){
$Authentication->Email=iconv("gb2312","utf-8",$email);
$Authentication->IsSendEMail=True;
}
$Authentication->AuthPWD="china_hei";




$AuthenticationInfo[0]->Sequence=0;
$AuthenticationInfo[0]->Authentication=$Authentication;




$array = new StdClass();
$array->Appkey = "obk_china_hei";
  $array->Ticket =$Ticket;
 $array-> CorporationID = "china_hei"; 
 $array-> AuthenticationInfoList= $AuthenticationInfo;
/*
$Authentication=[];


$Authentication[0]=[
"Sequence" => 0, 
"Authentication" => [
//"Uid"=>iconv("gb2312","utf-8","1"),
"EmployeeID"=>iconv("gb2312","utf-8",$byname),
"Name"=>iconv("gb2312","utf-8",$user_name),
"MobilePhone"=>iconv("gb2312","utf-8",$mobil_no),
"IdCardNo"=>iconv("gb2312","utf-8",$staff_card_no),
"Valid"=>"A",
//"RankName"=>iconv("gb2312","utf-8","工程师"),
"SubAccountName"=>iconv("gb2312","utf-8","china_hei_提前审批"),
"Email"=>iconv("gb2312","utf-8",$email),
"IsSendEMail"=>True,
"AuthPWD"=>"china_hei"

];
*/


/*
$renyuan=array();


$renyuan["Uid"]=iconv("gb2312","utf-8","1");
$renyuan["EmployeeID"]=iconv("gb2312","utf-8","liyunlong");
$renyuan["Name"]=iconv("gb2312","utf-8","liyunlong");
$renyuan["MobilePhone"]="18249035485";
$renyuan["IdCardNo"]="230231198910201835";
$renyuan["Valid"]="A";
$renyuan["RankName"]=iconv("gb2312","utf-8","工程师");
$renyuan["SubAccountName"]=iconv("gb2312","utf-8","china_hei_提前审批");
$renyuan["AuthPWD"]="liyunlong";


$para["Authentication"]=array();
$para["Authentication"]["Sequence"]=0;
$para["Authentication"]["AuthenticationInfoList"]=$renyuan;
//$para["AuthenticationInfoList"]["Authentication"]=$renyuan;
*/
echo "<pre>";
print_r($array);
echo "</pre>";
$url="https://ct.ctrip.com/corpservice/CorpCustService/SaveCorpCustInfoList"; 


//$resu = send_post($url,$para);
//$tttt = json_decode($resu);
//print_r($tttt);






 $data = json_encode($array);  
// $data='{ "Appkey":"obk_china_hei", "Ticket":"5b24ef0f90e1d370740370ce", "CorporationID":"china_hei", "Authentication":[ "Sequence":"0", "AuthenticationInfoList":{ "Uid":"1", "EmployeeID":"sunzhonghai1", "Name":"孙忠海", "MobilePhone":"18249035485", "IdCardNo":"230231198910201835", "Valid":"A", "RankName":"工程师", "SubAccountName":"china_hei_提前审批", "AuthPWD":"sun12345678" } ]}';
 echo $data."<hr>";   
 //exit;
//list($return_code, $return_content) = http_post_data($url, $data);  
//$url  = "http://192.168.0.104/hadian/2.php"; 


 
$aaa = http_post_data($url, $data);    
print_r($aaa);  
//echo $aaa;  
 echo "<hr>"; 
$ccc=json_decode($aaa);  
print_r($ccc);  
echo $ccc->Result;
if($ccc->Result=="Success"){

$query4="UPDATE `user` SET    `xiechengbianhao`='$byname' WHERE (`uid`='$uid')";


//echo $query."<br>";
//exit;
exequery(TD::conn(),$query4);


echo "<script>alert('开卡成功!');</script>";
echo "<script>location.href='index.php';<script>";
}
  
echo "<hr>";


function http_post_data($url, $data_string) {    
    
        $ch = curl_init();  

 
        curl_setopt($ch, CURLOPT_POST, 1);    //使用post方法
        curl_setopt($ch, CURLOPT_URL, $url);  
   curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //如果接口URL是https的,我们将其设为不验证,如果不是https的接口,这句可以不用加  
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //如果接口URL是https的,我们将其设为不验证,如果不是https的接口,这句可以不用加
   // curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); 
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);    
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(    
            'Content-Type: application/json; charset=utf-8',    
            'Content-Length: ' . strlen($data_string))    
        );   


        ob_start();    
        curl_exec($ch);    
        $return_content = ob_get_contents();    
        //echo $return_content."<br>";  
        ob_end_clean();    
    
        $return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);    
      //  return array($return_code, $return_content);   
// echo "1111"; 
      return  $return_content;  
 
    }    
 /*   
$url  = "http://127.0.0.1/2.php";    
$data = json_encode(array('a'=>"weqweqwe", 'b'=>2));     
    
//list($return_code, $return_content) = http_post_data($url, $data);  
$aaa = http_post_data($url, $data);    
//print_r($aaa);  
echo $aaa;  
  
$ccc=json_decode($aaa);  
print_r($ccc);  
echo $ccc->b;  
  
echo "<hr>";  
$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';  
var_dump(json_decode($json,true)); 
 */
/** Json数据格式化 
* @param  Mixed  $data   数据 
* @param  String $indent 缩进字符,默认4个空格 
* @return JSON 
*/  
function jsonFormat($data, $indent=null){  
   
    // 对数组中每个元素递归进行urlencode操作,保护中文字符  
    array_walk_recursive($data, 'jsonFormatProtect');  
   
    // json encode  
    $data = json_encode($data);  
   
    // 将urlencode的内容进行urldecode  
    $data = urldecode($data);  
   
    // 缩进处理  
    $ret = '';  
    $pos = 0;  
    $length = strlen($data);  
    $indent = isset($indent)? $indent : '    ';  
    $newline = "\n";  
    $prevchar = '';  
    $outofquotes = true;  
   
    for($i=0; $i<=$length; $i++){  
   
        $char = substr($data, $i, 1);  
   
        if($char=='"' && $prevchar!='\\'){  
            $outofquotes = !$outofquotes;  
        }elseif(($char=='}' || $char==']') && $outofquotes){  
            $ret .= $newline;  
            $pos --;  
            for($j=0; $j<$pos; $j++){  
                $ret .= $indent;  
            }  
        }  
   
        $ret .= $char;  
           
        if(($char==',' || $char=='{' || $char=='[') && $outofquotes){  
            $ret .= $newline;  
            if($char=='{' || $char=='['){  
                $pos ++;  
            }  
   
            for($j=0; $j<$pos; $j++){  
                $ret .= $indent;  
            }  
        }  
   
        $prevchar = $char;  
    }  
   
    return $ret;  
}  
 
 
 /** 将数组元素进行urlencode 
* @param String $val 
*/  
function jsonFormatProtect(&$val){  
    if($val!==true && $val!==false && $val!==null){  
        $val = urlencode($val);  
    }  
}  
    
?>
</body></html>

猜你喜欢

转载自blog.csdn.net/hai7425/article/details/80839095