1. 程式人生 > >EasyWeChat製作公眾號推送

EasyWeChat製作公眾號推送

<?php

namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Input;  
use Auth,Redirect;  
use Validator;  
use EasyWeChat\Factory;
use EasyWeChat\Foundation\Application;
use DB;  



/**
     * 微信推送
     * @param  Request
     * @return [json]
     */


    public function wxPush(Request $request)
    {

        $appid       =    config('wechat.appId');
        $secret      =    config('wechat.secret');
        $config = [
            'app_id' => $appid,
            'secret' => $secret,
            'response_type' => 'array',

        ];

        $app = new Application($config);


        $app->notice->send([
            'touser' => 'oFFxE1BofS*****',               //使用者openid
            'template_id' => '1KwPvazjT0_8*****6M5X8',    //模擬id
            'url' => 'https://easywechat.org',
            'data' => [
                'key1' => 'VALUE',
                'key2' => 'VALUE2'
            ],
        ]);
    }