php对接 微信公众号 基本操作
发表时间:2020-9-20
发布人:葵宇科技
浏览次数:58
文档https://developers.weixin.qq.com/doc/offiaccount/Cards_and_Offer/Distributing_Coupons_Vouchers_and_Cards.html
文档2https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html
文档3http://caibaojian.com/wxwiki/f5f7a96c36925a7b53a782762d51ebc5c2bb129b.html
签名校验工具https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=jsapisign
php代码
<?php
function curl_file_get_contents($durl){
// header传送格式
/*$headers = array(
"grant_type:client_credential",
"appid:APPID",
"secret:APPSECRET",
);*/
// 初始化
$curl = curl_init();
// 设置url路径
curl_setopt($curl, CURLOPT_URL, $durl);
// 将 curl_exec()获取的信息以文件流的形式返回,而不是直接输出。
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true) ;
// 在启用 CURLOPT_RETURNTRANSFER 时候将获取数据返回
curl_setopt($curl, CURLOPT_BINARYTRANSFER, true) ;
// 添加头信息
//curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
// CURLINFO_HEADER_OUT选项可以拿到请求头信息
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
// 不验证SSL
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
// 执行
$data = curl_exec($curl);
// 打印请求头信息
// echo curl_getinfo($curl, CURLINFO_HEADER_OUT);
// 关闭连接
curl_close($curl);
// 返回数据
var_dump($data);exit();
return $data;
}
curl_file_get_contents('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxc95d4e6b41ae81e8&secret=8ea6c716d28d5f1f94874537815bdde8');
<?php
function curl_file_post_contents($durl, $post_data){
// header传送格式
/*$headers = array(
"token:1111111111111",
"over_time:22222222222",
);*/
//初始化
$curl = curl_init();
//设置抓取的url
curl_setopt($curl, CURLOPT_URL, $durl);
//设置头文件的信息作为数据流输出
curl_setopt($curl, CURLOPT_HEADER, false);
//设置获取的信息以文件流的形式返回,而不是直接输出。
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
//设置post方式提交
curl_setopt($curl, CURLOPT_POST, true);
// 设置post请求参数
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
// 添加头信息
//curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
// CURLINFO_HEADER_OUT选项可以拿到请求头信息
curl_setopt($curl, CURLINFO_HEADER_OUT, true);
// 不验证SSL
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
//执行命令
$data = curl_exec($curl);
// 打印请求头信息
// echo curl_getinfo($curl, CURLINFO_HEADER_OUT);
//关闭URL请求
curl_close($curl);
var_dump($data);exit();
//显示获得的数据
return $data;
}
$post_data = [
'action_name'=>'QR_CARD',
'action_info'=>[
'card'=>[
'card_id'=>'pen536FYRHig_f0P2wrHpxCC3Awg'
]
]
];
$post_data = json_encode($post_data);
curl_file_post_contents('https://api.weixin.qq.com/card/qrcode/create?access_token=37_sCcKc39KJzNQJeTl4VNSHrB7KxbQReg3t3NFOCzU7dFTv8BLGTsDTY75nmQGpgcTDtZh_7rd6S1uaK2z2lFAdAe83eQcpMrgZKz2u5vbjjGEwxNIZzAwdWGe9T-B0apHE8wUKell0xxcxl64MVRhADAQZV',$post_data);
https://www.cnblogs.com/yclimb/p/10066720.html
https://www.cnblogs.com/ldms/p/5241756.html
https://blog.csdn.net/wechatcard/article/details/47980695
获取ticket,直接get请求即可
https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=37_937j8EQEUGloMOYRSqkO5DtN9O8vZcdAbEdqBKc2VglW6CeThkKA8Ctqs2KHJR548n1XPzZCKrKV-Uk6s5h4ac6MsqkEFNv-Tv00lHsu3ipDnQDmHD3Ar4uJeBogV4UPq0jqAb2-sIbr7l4hDIMcAJAQVZ&type=wx_card
注意jsapi_ticket的生成,别调到卡券ticket的生成接口了,type要传"jsapi"
https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=jsapi