使用html5本地存储优化网页请求

(function(s){
	if(s){
		var userCity = s.getItem("userCity");
		if( userCity == null ){
			$.get("/index/userCity",null,function(d){s.setItem("userCity",d);$("#AsyncUserCity").html(d)});
		}else{
			$("#AsyncUserCity").html(userCity);
		}
		var hotKeywords = s.getItem("hotKeywords");
		if( hotKeywords == null ){
			$.get("/index/hotKeywords",null,function(d){s.setItem("hotKeywords",d);$("#AsyncHotKeywords").html(d)});
		}else{
			$("#AsyncHotKeywords").html(hotKeywords);
		}
	}else{
		$("#AsyncUserCity").load("/index/userCity");
		$("#AsyncHotKeywords").load("/index/hotKeywords");
	}
})(window.sessionStorage);

php curl 并发请求

protected static function mCurl($urlArray){
	$mh = curl_multi_init();
	$chArray = [];
	foreach($urlArray as $url){
		$chArray[] = $ch = curl_init(strpos($url,'/')===0?API_URL.$url:$url);
		curl_setopt($ch, CURLOPT_TIMEOUT, 15);
		curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
		curl_multi_add_handle($mh, $ch);
	}
	curl_multi_exec($mh, $still_running);
	while($still_running){
		curl_multi_select($mh);
		curl_multi_exec($mh, $still_running);
	}
	$rsArray = [];
	foreach($chArray as $ch){
		$response = curl_multi_getcontent($ch);
		self::log(curl_getinfo($ch,CURLINFO_EFFECTIVE_URL)."\r\n".$response);
		$rsArray[] = json_decode($response, true);
		curl_multi_remove_handle($mh, $ch);
	}
	curl_multi_close($mh);
	return $rsArray;
}

php openssl(SHA1WithRSA) 签名 验签

签名:

public function wjSign($data){
	$key = openssl_pkey_get_private(file_get_contents($this->privateKeyPathWJ));
	openssl_sign($data, $sign, $key, OPENSSL_ALGO_SHA1);
	$sign = base64_encode($sign);
	return $sign;
}

验签:

public function wjVerify($data, $sign){
	$sign = base64_decode($sign);
	$key = openssl_pkey_get_public(file_get_contents($this->publicKeyPathWJ));
	$result = openssl_verify($data, $sign, $key, OPENSSL_ALGO_SHA1) === 1;
	return $result;
}

php openssl 分段 加密 解密

加密:

public function encrypt($data){
	$crypted = [];
	$data = json_encode($data);
	
	$publicKey = openssl_pkey_get_public(file_get_contents($this->publicKeyPath));
	$dataArray = str_split($data, 117);
	foreach($dataArray as $subData){
		$subCrypted = null;
		openssl_public_encrypt($subData, $subCrypted, $publicKey);
		$crypted[] = $subCrypted;
	}
	$this->log($data);
	return base64_encode(implode('',$crypted));
}

解密:

public function decrypt($data){
	$decrypted = [];
	$data = base64_decode($data);
	
	$privateKey = openssl_pkey_get_private(file_get_contents($this->privateKeyPath));
	$dataArray = str_split($data, 128);
	foreach($dataArray as $subData){
		$subDecrypted = null;
		openssl_private_decrypt($subData, $subDecrypted, $privateKey);
		$decrypted[] = $subDecrypted;
	}
	$decrypted = implode('',$decrypted);
	$this->log($decrypted);
	return json_decode($decrypted, true);
}