模板消息推送demo
$rs = json_decode(GetToken());
$template_id = ‘模板id’;
$m = M(“Member”);
$touser = openid
a
d
d
r
=
M
(
"
O
r
d
e
r
"
)
−
>
w
h
e
r
e
(
a
r
r
a
y
(
′
i
d
′
=
>
addr = M("Order")->where(array('id'=>
addr=M("Order")−>where(array(′id′=>id))->getField(‘address’);
//$touser = $openid;
$data = array(
“first”=>array(
“value”=>"",
“color”=>"#173177"
),
“keyword1”=>array(
“value”=>’’,
“color”=>"#173177"
),
“keyword2”=>array(
“value”=>’’,
“color”=>"#173177"
),
“keyword3”=>array(
“value”=>’’,
“color”=>"#173177"
),
“remark”=>array(
“value”=>"",
“color”=>"#173177"
)
);
c
o
n
t
e
n
t
=
a
r
r
a
y
(
"
t
o
u
s
e
r
"
=
>
content = array( "touser"=>
content=array("touser"=>touser,
“template_id”=>
t
e
m
p
l
a
t
e
i
d
,
"
u
r
l
"
=
>
"
跳
转
地
址
"
d
a
t
a
"
=
>
template_id, "url"=>"跳转地址 "data"=>
templateid,"url"=>"跳转地址"data"=>data
);
u
r
l
=
′
h
t
t
p
s
:
/
/
a
p
i
.
w
e
i
x
i
n
.
q
q
.
c
o
m
/
c
g
i
−
b
i
n
/
m
e
s
s
a
g
e
/
t
e
m
p
l
a
t
e
/
s
e
n
d
?
a
c
c
e
s
s
t
o
k
e
n
=
′
.
url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token='.
url=′https://api.weixin.qq.com/cgi−bin/message/template/send?accesstoken=′.access_token;
c
o
n
t
e
n
t
=
j
s
o
n
e
n
c
o
d
e
(
content = json_encode(
content=jsonencode(content);
c
h
=
c
u
r
l
i
n
i
t
(
)
;
c
u
r
l
s
e
t
o
p
t
(
ch = curl_init(); curl_setopt(
ch=curlinit();curlsetopt(ch, CURLOPT_URL,
u
r
l
)
;
c
u
r
l
s
e
t
o
p
t
(
url); curl_setopt(
url);curlsetopt(ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt(
c
h
,
C
U
R
L
O
P
T
S
S
L
V
E
R
I
F
Y
P
E
E
R
,
F
A
L
S
E
)
;
c
u
r
l
s
e
t
o
p
t
(
ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt(
ch,CURLOPTSSLVERIFYPEER,FALSE);curlsetopt(ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt(
c
h
,
C
U
R
L
O
P
T
P
O
S
T
,
1
)
;
c
u
r
l
s
e
t
o
p
t
(
ch, CURLOPT_POST, 1); curl_setopt(
ch,CURLOPTPOST,1);curlsetopt(ch, CURLOPT_POSTFIELDS, $content);
o
u
t
p
u
t
=
c
u
r
l
e
x
e
c
(
output = curl_exec(
output=curlexec(ch);
curl_close($ch);
return $output;