105 lines
3.6 KiB
PHP
105 lines
3.6 KiB
PHP
<?php
|
|
/**
|
|
* *
|
|
* * ============================================================================
|
|
* * Created by PhpStorm.
|
|
* * User: Ice
|
|
* * 邮箱: ice@sbing.vip
|
|
* * 网址: https://sbing.vip
|
|
* * Date: 2019/9/19 下午3:21
|
|
* * ============================================================================.
|
|
*/
|
|
|
|
namespace app\common\controller;
|
|
|
|
use think\App;
|
|
use think\Loader;
|
|
|
|
/**
|
|
* 微信推送.
|
|
*/
|
|
class WxTui
|
|
{
|
|
function __construct(){
|
|
|
|
}
|
|
|
|
public function cash_message($openid, $data){
|
|
// $appid = "wx0b3defb62f0f910b";
|
|
// $secret = "c02aa7ad9e4a5c423862e068b6cb4ad4";
|
|
$appid = "wx1f479720f02d3a39";
|
|
$secret = "064869826a4c2b64d78741e923246f68";
|
|
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$secret";
|
|
$token = $this->getJson($url);
|
|
$token = json_decode($token, true);
|
|
|
|
$uri ='https://api.weixin.qq.com/cgi-bin/message/template/send';
|
|
$access_token = $token["access_token"];
|
|
$uri = $uri.'?access_token='.$access_token;
|
|
|
|
$data= array('touser'=>$openid, //发给谁
|
|
'template_id'=>'G_tFTFVPqY5krFuZ59MBybGENuLw22imaJgE7ilhwOU', //模板id
|
|
'url'=>'#', //这个是你发送了模板消息之后,当用户点击时跳转的连接
|
|
'topcolor'=>"#FF0000", //颜色
|
|
'miniprogram' => '',
|
|
'data'=>array(
|
|
|
|
'first'=>array(
|
|
'value'=>$data['first'],
|
|
'color'=>'#173177'
|
|
),
|
|
'keyword1'=>array(
|
|
'value'=>$data['course_name'],
|
|
'color'=>'#173177'
|
|
),
|
|
'keyword2'=>array(
|
|
'value'=>$data['teacher_name'],
|
|
'color'=>'#173177'
|
|
),
|
|
'keyword3'=>array(
|
|
'value'=>$data['tel'],
|
|
'color'=>'#173177'
|
|
),
|
|
'keyword4'=>array(
|
|
'value'=>$data['time'],
|
|
'color'=>'#173177'
|
|
),
|
|
'remark'=>array(
|
|
'value'=>$data['remark'],
|
|
'color'=>'#173177'
|
|
)
|
|
)
|
|
);
|
|
$res_data = $this->getJson($uri,$data);
|
|
$res_data = json_decode($res_data, true);
|
|
if ($res_data['errcode'] != 0) {
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public function getJson($url = '', $param = [] ,$contentType = 'json'){
|
|
$ch = curl_init();
|
|
// 请求地址
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
// 请求参数类型
|
|
$param = $contentType == 'json' ? urldecode(json_encode($param)) : http_build_query($param);
|
|
// 关闭https验证
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
|
// post提交
|
|
if($param){
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
|
|
}
|
|
// 返回的数据是否自动显示
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
// 执行并接收响应结果
|
|
$output = curl_exec($ch);
|
|
// 关闭curl
|
|
curl_close($ch);
|
|
return $output !== false ? $output : false;
|
|
|
|
}
|
|
}
|