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

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

一、注册易客云

地址:http://www.yiketianqi.com/user/register
早安微信公众号消息推送最新版(国外城市、国内每日新闻)_第1张图片
复制下面的代码到百度云函数代码编辑页
早安微信公众号消息推送最新版(国外城市、国内每日新闻)_第2张图片

代码:


$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 "发送成功!
"
; }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}}

效果:
早安微信公众号消息推送最新版(国外城市、国内每日新闻)_第3张图片

你可能感兴趣的:(php,微信)