代码部分结合YII2但不影响使用
第一步:生成小程序码图片
第三步:将缩放后的小程序图片合成到背景图片
第一步:生成小程序码图片 (我使用的场景是无限制小程序码code地址 三种自行选择)
//微信小程序 小程序码 public static function getWeChatSmallProgramCode($scene { $AccessToken = self::getAccessToken(; $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=" . $AccessToken; $postData = [ 'scene' => $scene, 'page' => 'pages/index/index', 'width'=>930 ]; $postData = json_encode($postData; $contentData = self::sendPost($url, $postData; return $contentData; //如果图片大小符合这开启base64位图片地址也可以完成图片的合并合文字的合并 // return self::base64UrlCode($contentData, 'image/png'; } protected static function sendPost($url, $post_data { $options = array( 'http' => array( 'method' => 'POST', 'header' => 'Content-type:application/json', //header 需要设置为 JSON 'content' => $post_data, 'timeout' => 60 //超时时间 ; $context = stream_context_create($options; return file_get_contents($url, false, $context; } //二进制转图片image/png public static function base64UrlCode($contents, $mime { $base64 = base64_encode($contents; return ('data:' . $mime . ';base64,' .