-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathwxTPLMessage.php
More file actions
55 lines (48 loc) · 1.47 KB
/
Copy pathwxTPLMessage.php
File metadata and controls
55 lines (48 loc) · 1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
# 模板消息示例代码
include_once('./class/http.php');
include_once('./class/wxLoginClass.php');
$config = include_once('config.php');
//接收参数
$data = file_get_contents("php://input");
$data = json_decode($data,true);
$code = $_GET['code'];
//获取openid
$login = new WXLogin();
$loginRes = $login->login($code);
$openId = $loginRes['openid'];
//获取access_token
$tokenUrl = $config['TOKENURL'];
$tokenUrl = sprintf($tokenUrl, $config["WXAPPID"], $config["WXAPPSECRET"]);
$access_token = curl_get($tokenUrl);
$access_token = json_decode($access_token,true);
//发送模板消息
$tplMSG = array(
'touser' => $openId,
'form_id' => $data['formId'],
'page' => 'pages/setting/setting',
// 填入开发者选择的TemplateID
'template_id' =>'your template_id',
'data' => array(
'keyword1'=>array(
"value" => $data['formData']['place'],
"color" => '#333'
),
'keyword2'=>array(
"value" => $data['formData']['date'],
"color" => '#333'
),
'keyword3'=>array(
"value" => $data['formData']['name'],
"color" => '#333'
),
'keyword4'=>array(
"value" => $data['formData']['id'],
"color" => '#333'
)
),
"emphasis_keyword" => "keyword3.DATA"
);
$tplMSGUrl = sprintf($config['TPLMSGURL'],$access_token['access_token']);
$msgResult = curl_post($tplMSGUrl, $tplMSG);
echo($msgResult);