Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

test

<?php 
    #SETUP
    $A_type = 'POST'; //GET/POST
    $A_TOKEN = 0; // 0/1, 是否
	$A_Ctype = 'XML'; //JSON/XML

	#参数配置
	$apiid = 'crm1'; #签名ID
	$apiurl = 'https://api.mgsforex.com/crmv2/WebAPI/Public/listsub'; //登录入口,需与接口端保持一致
	$apikey = 'v66YKULHFld2JElhm'; //签名ID专属md5加盐
	$reskey = array('account','password'); //设置需要用BASE64转码的参数(涉及中文或空格特殊符号的参数),需与接口端保持一致
	$apitime =  apitime('https://api.mgsforex.com/crmv2/WebAPI/Public/servertime'); //获取接口端时间

	#将要传输的参考值
    $array = array(
		"apiid" => $apiid,
		"apitime" => $apitime,
		"apictype" => $A_Ctype,
		'account' => '88058914',
		'password' => 'qwe123'
    );

    #API数据获取
	if($A_type == 'GET'){
    	#处理传参
    	ksort($array); //给array里面的值按照首字母排序,如果首字母一样看第二个字母   以此类推...
    	$newurl = $apiurl.'?'.signMsg($array, $reskey); //组装成新的URL
    	$newurl = $newurl.'&apisign='.MD5($newurl.$apikey); //组装成新的URL, 加签

    	#接收接口信息
    	$content = file_get_contents($newurl);
        if($A_RTtype =='JSON') $content = json_decode($content,TRUE); //JSON格式需解码转ARRAY
		if($A_RTtype =='XML') header("Content-type:text/xml"); //返回XML需输出头信息
		print_r($content);
	}elseif($A_type == 'POST'){
        #处理传参
        ksort($array); //给array里面的值按照首字母排序,如果首字母一样看第二个字母   以此类推...
        $newurl = $apiurl.'?'.signMsg($array, $reskey); //组装成新的URL
		$array['apisign'] = MD5($newurl.$apikey);
        foreach ($reskey as $reskeys){
            if(isset($array[$reskeys])){
                $array[$reskeys] = base64_encode($array[$reskeys]);
            }
        }
        #print_r($newurl);
        include 'HttpClient.class.php'; //引入HTTPCLIENT类
        $content = HttpClient::quickPost($apiurl, $array);
        if($A_Ctype =='JSON') $content = json_decode($content,TRUE); //JSON格式需解码转ARRAY
		if($A_Ctype =='XML') header("Content-type:text/xml"); //返回XML需输出头信息
		print_r($content);
    }else{
        exit('null');
    }
	
    
    /**
     * 设置加签数据
     * 
     * @param unknown $array
     * @param unknown $md5Key
     * @return string
     */
    function signMsg($array,$reskey){
        $msg = "";
        $i = 0;
        // 转换为字符串 key=value&key.... 加签
        foreach ($array as $key => $val) {
            // 不参与签名
            if($key != "apisign" && $key != "apitoken"){
				if(in_array($key,$reskey)){
					$temval = base64_encode($val); //特殊参数用BASE64转码
				}else{
					$temval = $val;
				}
				
                if($i == 0 ){
                    $msg = $msg."$key=$temval";
                }else {
                    $msg = $msg."&$key=$temval";
                }
                $i++;
            }
        }
        return  $msg;
    }
    
    function apitime($url){
		$content = file_get_contents($url);
		$content = json_decode($content,TRUE);
		
        return  $content['data'];
    }
   
?>

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.