地址:https://login.bce.baidu.com/?redirect=https%3A%2F%2Fconsole.bce.baidu.com%2Fcfc%2F%3F_%3D1661492571497#/cfc/functions
空白函数,函数名称自定义,运行时选 PHP7.2(其他默认),下一步,提交。
$appId = 'ghjdghjnghm'; //对应自己的appId
$appSecret = 'rtyhrtehrthrthtrhtr'; //对应自己的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('0000-00-00');
$end = time();
$love = ceil(($end - $lovestart) / 86400);
// 下一个生日是哪一天(格式别错)
$birthdaystart = strtotime('0000-00-00');
$end = time();
$diff_days = ($birthdaystart - $end);
$birthday = (int)($diff_days/86400);
$birthday = str_replace("-", "", $birthday);
$tianqiurl = 'https://api.youguo56.com/api/wether/?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 = 'fgnhfdgnfghn'; //这个填你女朋友的openid
$data = array(
'touser' => $touser,
'template_id' => "fdbnnfgdnfgnfghng", //改成自己的模板id,在微信后台模板消息里查看
'data' => array(
'first' => array(
'value' => $yjh,
'color' => "#00BFFF"
),
'keyword8' => array(
'value' => $tianqi['data']['forecast']['0']['date'],
'color' => "#1E90FF"
),
'keyword1' => array(
'value' => $tianqi['data']['city'],
'color' => "#7B68EE"
),
'keyword2' => array(
'value' => $tianqi['data']['forecast']['0']['type'],
'color' => "#FFA07A"
),
'keyword3' => array(
'value' => $tianqi['data']['forecast']['0']['high'],
'color' => "#98FB98"
),
'keyword4' => array(
'value' => $tianqi['data']['forecast']['0']['low'],
'color' => "#F4A460"
),
'keyword5' => array(
'value' => $love . '天',
'color' => "#FA8072"
),
'keyword6' => array(
'value' => $birthday . '天',
'color' => "#F5DEB3"
),
'keyword7' => array(
'value' => $tianqi['data']['ganmao'],
'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://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index
今天是{{keyword8.DATA}}
城市:{{keyword1.DATA}}
天气:{{keyword2.DATA}}
最高温度:{{keyword3.DATA}}
最低温度:{{keyword4.DATA}}
今天是我们在一起的第{{keyword5.DATA}}
距离宝贝的生日还有{{keyword6.DATA}}
今日建议:{{keyword7.DATA}}
每日一句:
{{remark.DATA}}
定时触发器以UTC时间运行,即北京时间减去8个小时
这里的计划表达式为 cron(0 23 * * ?)
每天下午的 23:00 (UTC) 触发;对应北京为每天早上07:00执行
开启定时触发器,这样就完成啦!
期待下次的分享,别忘了三连支持博主呀~
我是 念舒_C.ying ,期待你的关注~