微信公众号分享功能

1.composer 引入 easyWeChat架包 composer require overtrue/wechat:~4.0 -vvv (文档地址 https://www.easywechat.com/docs/4.1/basic-services/jssdk
)

  1. 控制器实例化 操作类 并返回数据
    public function index()
    {
        //公众号配置信息
        $config = [
            'app_id' => env('WECHAT_OFFICIAL_ACCOUNT_APPID'),
            'secret' => env('WECHAT_OFFICIAL_ACCOUNT_SECRET'),
            'response_type' => 'array',
        ];

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

        $result = $app->jssdk->buildConfig([],false,false, $json = true);//获取分享所需参数

        $result = json_decode($result,true);
        /**
         * 分享返回的参数
         */
        $nonceStr = $result['nonceStr'];
        $timestamp = $result['timestamp'];
        $url = $result['url'];
        $signature = $result['signature'];

        return view('test',compact('nonceStr','timestamp','url','signature')); //传递到页面上

    }

3.页面js处理


你可能感兴趣的:(微信公众号分享功能)