获取小程序scheme码,适用于短信、邮件、外部网页等拉起小程序的业务场景

这里属于HTTPS调用    贴它!

注意:access_token参数在URL中体现,其它参数写在POST请求的body中!

获取小程序scheme码,适用于短信、邮件、外部网页等拉起小程序的业务场景

 

 

 

<?php /** * 第一步 获取access_token * $appid:开发者ID(AppID) * $appsecret:开发者密码(AppSecret) * * 返回access_token、有效时间 */ function wx_xcx_code($appid, $appsecret){ // 获取access_token、有效时间 $access_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$appsecret; $access_info = json_decode(file_get_contents($access_url),true); return $access_info; } /** * 第二步 拼接接口及请求参数 调用POST请求 返回结果 */ function getUrlScheme(){ $access_token = wx_xcx_code("开发者ID-AppID", "开发者密码-AppSecret"); $access_token = $access_token['access_token']; // 加个判断,是否获取成功 $url = "https://api.weixin.qq.com/wxa/generatescheme?access_token=" . $access_token; $path = '/pages/index/index'; //query 跳转传递的参数 $scene = 'id=19'; $post_data = [ 'jump_wxa' => [ 'path' => $path, 'query' => $scene ], 'is_expire' => true, 'expire_time' => 1614428797 ]; $post_data = json_encode($post_data); $result = api_notice_increment($url, $post_data); print_r(json_decode($result)); } /** * 发起 POST 请求微信接口 * https://api.weixin.qq.com/wxa/generatescheme?access_token=ACCESS_TOKEN * * 返回结果 */ function api_notice_increment($url, $data){ $ch = curl_init(); $header = ["Accept-Charset" => "utf-8"]; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_AUTOREFERER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $tmpInfo = curl_exec($ch); // var_dump($tmpInfo); if (curl_errno($ch)) { return false; } else { // var_dump($tmpInfo); return $tmpInfo; } } // 调用 打印结果 $ok = getUrlScheme(); print_r($ok); ?>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wspxjz.html