地址:https://login.bce.baidu.com/?redirect=https%3A%2F%2Fconsole.bce.baidu.com%2Fcfc%2F%3F_%3D1661492571497#/cfc/functions
空白函数,函数名称自定义,运行时选 PHP7.2(其他默认),下一步,提交。
$appId = 'abcdefgh'; //对应自己的appId
$appSecret = 'abcdefgh '; //对应自己的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('2022-06-16');
$end = time();
$love = ceil(($end - $lovestart) / 86400);
//Z 下一个生日是哪一天(格式别错)
$birthdaystart = strtotime('2023-02-24');
$end = time();
$diff_days = ($birthdaystart - $end);
$Zbirthday = (int)($diff_days/86400);
$Zbirthday = str_replace("-", "", $Zbirthday);
// C下一个生日是哪一天(格式别错)
$birthdaystart = strtotime('2023-04-19');
$end = time();
$diff_days = ($birthdaystart - $end);
$birthday = (int)($diff_days/86400);
$birthday = str_replace("-", "", $birthday);
$tianqiurl = 'https://v0.yiketianqi.com/api?unescape=1&version=v63&language=zh&city=兰州&appid=111111&appsecret=1111111'; //修改为自己的
$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 = 'Z_C恋爱日记'; //可以留空 也可以写上一句
$touser = 'abcdefgh '; //这个填你女朋友的openid
$data = array(
'touser' => $touser,
'template_id' => "abcdefgh ", //改成自己的模板id,在微信后台模板消息里查看
'data' => array(
'first' => array(
'value' => $yjh,
'color' => " #FFB6C1"
),
'keyword1' => array(
'value' => $tianqi['date'], //日期
'color' => "#1E90FF"
),
'keyword10' => array(
'value' => $tianqi['week'],//星期
'color' => "#1E90FF"
),
'keyword11' => array(
'value' => $tianqi['update_time'],//时间
'color' => "#1E90FF"
),
'keyword2' => array(
'value' => $tianqi['city'],//城市
'color' => "#DC143C"
),
'keyword20' => array(
'value' => $tianqi['country'],//国家
'color' => "#DC143C"
),
'keyword3' => array(
'value' => $tianqi['wea'],//今日天气
'color' => "#6495ED"
),
'keyword30' => array(
'value' => $tianqi['win'],//风
'color' => "#6495ED"
),
'keyword4' => array(
'value' => $tianqi['hours']['0']['wea'],//现在天气
'color' => "#4169E1"
),
'keyword40' => array(
'value' => $tianqi['hours']['0']['win'],//现在风
'color' => "#4169E1"
),
'keyword5' => array(
'value' => $tianqi['tem1'],//高温
'color' => "#FF7F50"
),
'keyword50' => array(
'value' => $tianqi['tem2'],//低温
'color' => "#AFEEEE"
),
'keyword6' => array(
'value' => $tianqi['sunrise'],//日出
'color' => "#FFDEAD"
),
'keyword60' => array(
'value' => $tianqi['sunset'],//日落
'color' => "#FFA500"
),
'keyword7' => array(
'value' => $love . '天',
'color' => "#FA8072"
),
'keyword8' => array(
'value' => $Zbirthday . '天',
'color' => "#F5DEB3"
),
'keyword80' => array(
'value' => $birthday . '天',
'color' => "#F5DEB3"
),
'keyword9' => array(
'value' => $tianqi['air_tips'],//小贴士
'color' => "#FFB6C1"
),
'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 "发送成功!
";
}else {
echo "发送失败!请检查代码!!!
";
}
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) {
# 啥都没有 就是为了填执行失败的坑
# return $ret;
}
地址:http://www.yiketianqi.com/user/register
注册地址: http://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index
将下面的代码复制到模板内容里
模板标题自定义(可以把这个心的表情复制上)❤
{{first.DATA}}
现在是{{keyword1.DATA}} {{keyword10.DATA}} {{keyword11.DATA}}
国家:{{keyword20.DATA }}
城市:{{keyword2.DATA}}
今日天气:{{keyword3.DATA}} {{keyword30.DATA}}
现在天气:{{keyword4.DATA}} {{keyword40.DATA}}
最高温度:{{keyword5.DATA}} ℃
最低温度:{{keyword50.DATA}} ℃
日出:{{keyword6.DATA}}
日落:{{keyword60.DATA}}
今天是我们在一起的第 {{keyword7.DATA}}
距离Z.jie的生日还有 {{keyword8.DATA}}
距离C.ying的生日还有 {{keyword80.DATA}}
小贴士:{{keyword9.DATA}}
每日一句: {{remark.DATA}}
模板中的文字可以自定义修改,每一句括号后面的字段不要修改
定时触发器以UTC时间运行,即北京时间减去8个小时
这里的计划表达式为 cron(0 23 * * ?)
每天下午的 23:00 (UTC) 触发;对应北京为每天早上07:00执行
开启定时触发器,这样就完成啦!
期待下次的分享,别忘了三连支持博主呀~
我是 念舒_C.ying ,期待你的关注~