微信签名验证自动排序(数组字典排序)
- ksort();根据键对数组进行升序排序(a-z)
#签名参数 我这以支付签名为例
$signArray = array(
'appid' => $this->appid, //appid
'mch_id' => $this->mch_id,
'nonce_str' => $this->createNoncestr(), //生成随机字符串
'out_trade_no' => 'order',
'body' => $orderinfo['body'],
"total_fee" => $orderinfo ['price']*100,
"notify_url" => $this->notify_url,
"spbill_create_ip" => $this->getIp(),
"trade_type" => "MWEB",
);
#基本上签名都是需要进行字典排序
$boo = ksort($signArray)//成功签名排序 (成功-true,失败-false)
if(!$boo){
return '签名排序失败';
}
http_build_query($signArray);//生成URL-encode字符串