123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace app\api\controller;
- use EasyWeChat\Factory;
- use think\cache\driver\Redis;
- use think\Session;
- use think\Db;
- class WeChart {
- protected $app_id ='wx4ccfaf737dd24004';
- protected $app_secret = 'a7a7e0e7e3ce132f751e85202a09e0dc';
- /**
- * 获取token
- * @return mixed|string
- */
- public function getAccessToken()
- {
- $session = new Session();
- $over_time = $session->get('token_over_time');
- if($over_time < time()) {
- $url= "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$this->app_id}&secret={$this->app_secret}";
- $ret = http_curl($url);
- $session->set('access_token',$ret['access_token']);
- $session->set('token_over_time',time() +$ret['expires_in'] );
- }
- return $session->get('access_token');
- }
- public function sendMsg($openid,$jump_url)
- {
- $access_token = $this->getAccessToken();
- $url='https://api.weixin.qq.com/cgi-bin/message/wxopen/template/uniform_send?access_token='.$access_token;
- $data=[
- 'touser'=>$openid,
- 'mp_template_msg'=>[
- "appid"=>"wx8e881917d7c4c283",// 公众号
- "template_id"=>"2n42cwWat6UsokuOd9uqYAKIOF4Jbezw7hwVht11pz4",
- "url"=>$jump_url,
- 'miniprogram'=>[
- "appid"=>"wx4ccfaf737dd24004",// 小程序
- ],
- 'data'=>[
- 'first'=>[
- "value"=>'一剑霜寒',
- "color"=>"#173177"
- ],
- 'keyword1'=>[
- "value"=>'临沂',
- "color"=>"#173177"
- ],
- 'keyword2'=>[
- "value"=>'2021-10-20',
- "color"=>"#173177"
- ],
- 'keyword3'=>[
- "value"=>'20:30',
- "color"=>"#173177"
- ],
- 'keyword4'=>[
- "value"=>'李白刷野',
- "color"=>"#173177"
- ],
- 'keyword5'=>[
- "value"=>'20:30',
- "color"=>"#173177"
- ],
- 'remark'=>[
- "value"=>'屋里割草',
- "color"=>"#173177"
- ]
- ]
- ],
- ];
- $res = http_curl($url,'post',$data);
- }
- }
|