一、准备
corpid secret
二、获取access_token
https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$corpid&corpsecret=$secret
三、根据 access_token 获取ticket
https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket?access_token=$token
四、计算签名
//随机字符串
$str = time() . rand(111111,999999). 'sqsg';
$nonce_str = substr( md5($str),5,8 );
$timestamp = time(); //当前时间戳
$url = $req['url']; # 前端传过来的url 当前的页面的url 不含参数
$data = [
'jsapi_ticket' => $ticket,
'noncestr' => $nonce_str,
'timestamp' => $timestamp,
'url' => $url
];
$param = "";
foreach($data as $k=>$v){
$param .= $k.'='.$v.'&';
}
$p = rtrim($param,'&');
//计算签名
$signature = sha1($p);
$response['nonce_str'] = $nonce_str; #随机数
$response['timestamp'] = $timestamp; #时间戳
$response['signature'] = $signature; #签名
$response['url'] = $url; #跳转链接
$response['appid'] = corpid; #企业号ID
echo json_encode($response);