首先到微信小程序平台配置服务器信息
小程序必须是验证的,而且已经发布审核过的页面路径
创建Wxcode类
生成小程序码业务类
<?php
declare (strict_types = 1);
namespace app\controller\Index;
class Wxcode
{
public function getAccesstoken(){
$appid = ''; /*字符串小程序appid*/
$srcret = ''; /*字符串小程序秘钥*/
$tokenUrl="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$srcret;
$getArr=array();
$tokenArr=json_decode($this->send_post($tokenUrl,$getArr,"GET"));
$access_token=$tokenArr->access_token;
return $access_token;
}
public function send_post($url, $post_data,$method='POST') {
$postdata = http_build_query($post_data);
$options = array(
'http' => array(
'method' => $method, //or GET
'header' => 'Content-type:application/x-www-form-urlencoded',
'content' =>