1对数组进行排序[用法sign($data)]
function paixu($data1){
ksort($data1);
$rows = [];
foreach ($data1 as $key => $value) {
if (! $value || $key == 'sign') {
continue;
}
$rows[] = "{$key}={$value}";
}
$s = implode('&', $rows);
$s .= $appSecret;
return $s;
}
2.重定向到变量$url所指向的地址
header("Location: $url");
3.http_build_query()这个自己百度,返回js跳转代码,地址为变量$url。
$string = http_build_query($data);
$url = 'http://pay.forwe.co/submit.php?' . $string . '&sign=' . $sign . '&sign_type=MD5';
$result = "wind()ow.location.href='".$url."';";
4.
协议判断,用法($this->isHTTPS() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST']直接返回当前网址。
public function isHTTPS()
{
define('HTTPS', false);
if (defined('HTTPS') && HTTPS) {
return true;
}
if (!isset($_SERVER)) {
return false;
}
if (!isset($_SERVER['HTTPS'])) {
return false;
}
if ($_SERVER['HTTPS'] === 1) { //Apache
return true;
}
if ($_SERVER['HTTPS'] === 'on') { //IIS
return true;
}
if ($_SERVER['SERVER_PORT'] == 443) { //其他
return true;
}
return false;
}
5.post提交数据
//post提交函数
function post($url,$data) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}