大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
给女友的微信公众号消息推送
成都创新互联专注于岭东企业网站建设,响应式网站开发,购物商城网站建设。岭东网站建设公司,为岭东等地区提供建站服务。全流程定制制作,专业设计,全程项目跟踪,成都创新互联专业和态度为您提供的服务
跟上次的大致相同、新增了每日新闻、国外天气,修改了一部分代码
一、注册易客云
地址:http://www.yiketianqi.com/user/register
复制下面的代码到百度云函数代码编辑页
$appId = ''; //对应自己的appId
$appSecret = ''; //对应自己的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 "发送成功!
";
}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;
}
复制自己的appid和 appsecret 换成自己的appid、appsecret、城市
新模板内容
现在是{{keyword1.DATA}}
国家:{{keyword2.DATA}}
城市:{{keyword3.DATA}}
天气:{{keyword4.DATA}}
最高温度:{{keyword5.DATA}} ℃
最低温度:{{keyword6.DATA}} ℃
今天是我们在一起的第{{keyword8.DATA}}
距离宝贝的生日还有{{keyword9.DATA}}
每日一句: {{remark.DATA}}
在这里新增了每日新闻,如果不想要可以删掉这代码。
测试成功
期待下次的分享,别忘了三连支持博主呀~
我是 念舒_C.ying ,期待你的关注~????????????