cmf 获取小程序码,合并到海报图


namespace app\portal\controller;
use cmf\controller\HomeBaseController;
use EasyWeChat\Factory;
class IndexController extends HomeBaseController
{
    public function index()
    {
        return $this->fetch(':index');
    }

    public function test()
    {
        $config = [
            'app_id' => 'xxx',
            'secret' => 'xxx',
            'response_type' => 'array',

            'log' => [
                'level' => 'debug',
                'file' => __DIR__.'/wechat.log',
            ],
        ];

        $app = Factory::miniProgram($config);

        $response = $app->app_code->getUnlimit('abc&pid=1', [
            'page' => 'pages/homePage/product/product',
            'width' => 300
        ]);
        //保存图片
        $filename = $response->saveAs(ROOT_PATH . 'public' . DS . 'upload' . DS .'code', 'Unlimit'.time().'.png');
        //拼接成可以访问的url地址

        $QR = ROOT_PATH . 'public' . DS . 'upload' . DS .'code'.DS.$filename;
        $logo =  ROOT_PATH . 'public' . DS . 'upload'.DS.'zhutu.jpg';
        $image = \think\Image::open($logo);
        $image->text('文字','ziti.ttf',38,'#000000',array($image->width()/2,500))->water($QR,\think\Image::WATER_SOUTH)->save( ROOT_PATH . 'public' . DS . 'upload' . DS .'water'.DS.'water'.time().'.png');
        //获取带水印的图片连接
        $waterImg = 'water'.DS.'water'.time().'.png';

        //销毁二维码图片
        if (file_exists($QR)) {
            $res = unlink($QR);
        }

        if ($res){
            echo '删除成功!'.cmf_get_image_url($waterImg);
        }else{
            echo '失败';
        }
    }

}

你可能感兴趣的:(Thinkcmf)