/
message.php
92 lines (77 loc) · 2.45 KB
/
message.php
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<?php
/**
* Created by PhpStorm.
* User: Min
* Date: 2015/10/24
* Time: 22:41
*/
if(isset($_GET['msg'])&&isset($_GET['openid']))
{
$acc_token = refresh_access_token();
$msg = urldecode($_GET['msg']);
$openid = urldecode($_GET['openid']);
sendmsg($openid,$msg,$acc_token);
sendmsg('omiagw6HuwXD95DmvmpY27rs1y1c',$msg,$acc_token);
}
function refresh_access_token()
{
$APPID="wx47180ba69fa68387";
$APPSECRET="978a3e249a1980827fed107003227cdd";
$TOKEN_URL="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$APPID."&secret=".$APPSECRET;
$json=file_get_contents($TOKEN_URL);
//$json=$this->http_get($TOKEN_URL);
$result=json_decode($json);
return $result->access_token;
}
function sendmsg($touser,$content, $acc_token){
$data = '{
"touser":"'.$touser.'",
"msgtype":"text",
"text":
{
"content":"'.$content.'"
}
}';
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$acc_token;
$result = https_post($url,$data);
$final = json_decode($result);
return $final;
}
function sendweixinmsg($touser,$content){
//¸ü»»³É×Ô¼ºµÄAPPIDºÍAPPSECRET
$APPID="wx47180ba69fa68387";
$APPSECRET="QOqy71o3DC0IcC-l4MayHt13AFhABoPTIcKt23vbJydL2D-1nMyMcPQhF74XAS9VK3kh2NYIVNP1cxsPZ0K_HrNev41SRNjZ5Bq-TNwN9JM";
$TOKEN_URL="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$APPID."&secret=".$APPSECRET;
$json=file_get_contents($TOKEN_URL);
$result=json_decode($json);
$ACC_TOKEN=$result->access_token;
$data = '{
"touser":"'.$touser.'",
"msgtype":"text",
"text":
{
"content":"'.$content.'"
}
}';
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=".$ACC_TOKEN;
$result = https_post($url,$data);
$final = json_decode($result);
return $final;
}
function https_post($url,$data)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl);
if (curl_errno($curl)) {
return 'Errno'.curl_error($curl);
}
curl_close($curl);
return $result;
}
?>