給女友的微信公眾號消息推送
成都創(chuàng)新互聯(lián)專注于嶺東企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站開發(fā),購物商城網(wǎng)站建設(shè)。嶺東網(wǎng)站建設(shè)公司,為嶺東等地區(qū)提供建站服務(wù)。全流程定制制作,專業(yè)設(shè)計,全程項目跟蹤,成都創(chuàng)新互聯(lián)專業(yè)和態(tài)度為您提供的服務(wù)
跟上次的大致相同、新增了每日新聞、國外天氣,修改了一部分代碼
一、注冊易客云
地址:http://www.yiketianqi.com/user/register
復(fù)制下面的代碼到百度云函數(shù)代碼編輯頁
$appId = ''; //對應(yīng)自己的appId
$appSecret = ''; //對應(yīng)自己的appSecret
$wxgzhurl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" . $appId . "&secret=" . $appSecret;
$access_token_Arr = https_request($wxgzhurl);
$access_token = json_decode($access_token_Arr, true);
$ACCESS_TOKEN = $access_token['access_token']; //ACCESS_TOKEN
// 什么時候戀愛的(格式別錯)
$lovestart = strtotime('2012-12-22');
$end = time();
$love = ceil(($end - $lovestart) / );
// 下一個生日是哪一天(格式別錯)
$birthdaystart = strtotime('2023-12-02');
$end = time();
$diff_days = ($birthdaystart - $end);
$birthday = (int)($diff_days/);
$birthday = str_replace("-", "", $birthday);
$tianqiurl = 'https://yiketianqi.com/api?version=v5&appid=&appsecret=&city=堪培拉'; //修改為自己的測試
$tianqiapi = https_request($tianqiurl);
$tianqi = json_decode($tianqiapi, true);
$qinghuaqiurl = 'https://api.youguo56.com/api/chp/';
$qinghuaapi = https_request($qinghuaqiurl);
#$qinghua = json_decode($qinghuaapi, true);
$yjh = '';
$touser = 'vfvfvfv'; //這個填你女朋友的openid
$data = array(
'touser' => $touser,
'template_id' => "regrgagff", //改成自己的模板id,在微信后臺模板消息里查看
'url'=>"https://api.youguo56.com/api/60s/",
'data' => array(
'first' => array(
'value' => $yjh,
'color' => "#00BFFF"
),
'keyword1' => array(
'value' => $tianqi['update_time'],//時間
'color' => "#1E90FF"
),
'keyword2' => array(
'value' => $tianqi['country'],//國家
'color' => "#7B68EE"
),
'keyword3' => array(
'value' => $tianqi['city'],//城市
'color' => "#7B68EE"
),
'keyword4' => array(
'value' => $tianqi['data']['0']['wea'],//天氣
'color' => "#FFA07A"
),
'keyword5' => array(
'value' => $tianqi['data']['0']['tem1'],//高溫
'color' => "#98FB98"
),
'keyword6' => array(
'value' => $tianqi['data']['0']['tem2'],//低溫
'color' => "#98FB98"
),
'keyword8' => array(
'value' => $love . '天',
'color' => "#FA8072"
),
'keyword9' => array(
'value' => $birthday . '天',
'color' => "#F5DEB3"
),
'remark' => array(
'value' => $qinghuaapi,
'color' => "#6495ED"
),
)
);
$json_data = json_encode($data);
$url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" . $ACCESS_TOKEN;
$res = https_request($url, urldecode($json_data));
$res = json_decode($res, true);
if ($res['errcode'] == 0 && $res['errcode'] == "ok") {
echo "發(fā)送成功!
";
}else {
echo "發(fā)送失?。≌垯z查代碼?。。?br/>";
}
function https_request($url, $data = null)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
function handler($context) {
# 啥都沒有 就是為了填執(zhí)行失敗的坑
# return $ret;
}
復(fù)制自己的appid和 appsecret 換成自己的appid、appsecret、城市
新模板內(nèi)容
現(xiàn)在是{{keyword1.DATA}}
國家:{{keyword2.DATA}}
城市:{{keyword3.DATA}}
天氣:{{keyword4.DATA}}
最高溫度:{{keyword5.DATA}} ℃
最低溫度:{{keyword6.DATA}} ℃
今天是我們在一起的第{{keyword8.DATA}}
距離寶貝的生日還有{{keyword9.DATA}}
每日一句: {{remark.DATA}}
在這里新增了每日新聞,如果不想要可以刪掉這代碼。
測試成功
期待下次的分享,別忘了三連支持博主呀~
我是 念舒_C.ying ,期待你的關(guān)注~????????????