写一个php代码接收第三方推送的component_verify_ticket后返回字符串 success,然后获取component_access_token并储存到一个文件
时间: 2023-03-15 16:19:21 浏览: 114
<?php
$verifyTicket = $_GET["component_verify_ticket"];
if(!empty($verifyTicket)){
$fp = fopen("component_verify_ticket.txt","w");
fwrite($fp,$verifyTicket);
fclose($fp);
// 获取 component_access_token
$url = "https://api.weixin.qq.com/cgi-bin/component/api_component_token";
$data = array(
"component_appid" => "appid",
"component_appsecret" => "appsecret",
"component_verify_ticket" => $verifyTicket
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);
$result = json_decode($result,true);
if(!empty($result['component_access_token'])){
//将component_access_token保存到文件中
$fp = fopen("component_access_token.txt","w");
fwrite($fp,$result['component_access_token']);
fclose($fp);
echo "success";
}
}
阅读全文