早安微信公众号消息推送最新版(国外城市、国内每日新闻)

给女友的微信公众号消息推送

一、注册易客云

地址:http://www.yiketianqi.com/user/register
在这里插入图片描述
复制下面的代码到百度云函数代码编辑页
在这里插入图片描述

代码:
<?php
$appId = '2323232'; //对应自己的appId
$appSecret = '343444453'; //对应自己的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) / 86400);
 
// 下一个生日是哪一天(格式别错)
$birthdaystart = strtotime('2023-12-02');
$end = time();
$diff_days = ($birthdaystart - $end);
$birthday = (int)($diff_days/86400);
$birthday = str_replace("-", "", $birthday);
 
$tianqiurl = 'https://yiketianqi.com/api?version=v5&appid=12345678&appsecret=12345678&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 "发送成功!<br/>";
}else {
        echo "发送失败!请检查代码!!!<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) {
 
# 啥都没有   就是为了填执行失败的坑
    # return $ret;
}
 

复制自己的appid和 appsecret 换成自己的appid、appsecret、城市
在这里插入图片描述
新模板内容

现在是{{keyword1.DATA}} 
国家:{{keyword2.DATA}} 
城市:{{keyword3.DATA}} 
天气:{{keyword4.DATA}} 
最高温度:{{keyword5.DATA}} ℃
最低温度:{{keyword6.DATA}} ℃
今天是我们在一起的第{{keyword8.DATA}} 
距离宝贝的生日还有{{keyword9.DATA}} 
每日一句: {{remark.DATA}}

效果:
在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员-南

你的鼓励将是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值