吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 872|回复: 3
收起左侧

[学习记录] 小程序订阅消息

[复制链接]
90y6u 发表于 2022-8-11 17:05
/* 发送小程序订阅消息 */
    function xcxSendMsg($arr=[])
    {
        
        $access_token = isset($access_info['access_token']) ? $access_info['access_token'] : '';
        $apiurl = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token='.$access_token;
        $https_data['template_id'] = isset($arr['template_id']) ? $arr['template_id'] : '';
        $https_data['page'] = isset($arr['page']) ? $arr['page'] : '';
        $https_data['touser'] = isset($arr['touser']) ? $arr['touser'] : '';
        $https_data['miniprogram_state'] = 'formal';
        $https_data['lang'] = 'zh_CN';
        $https_data['data'] = $arr['data'];
        $data = json_encode($https_data);
        $res = $this->fetchContent($apiurl, 'POST', $data);
        return json_decode($res, true);
    }
/**
     * 发送curl请求
     * @param  string $url    请求地址
     * @param  string $method 请求方式 可选值:POST、GET
     * @param  string $body   向目标服务器发送的参数 (可选)
     * @param  string $header 指定请求头 (可选)
     * @return string         响应信息
     */
    function fetchContent($url, $method = 'GET', $body = array(), $header = array())
    {
        $ch = curl_init();
        if ($method == 'POST') {
            curl_setopt($ch, CURLOPT_POST, 1); //post提交方式
            curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
        } else {
            if (!empty($body)) {
                $url .= (strpos($url, '?') === false ? '?' : '&') . http_build_query($body);
            }
        }
        if (!empty($header)) {
            curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
        }
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_TIMEOUT, 5);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        if (substr($url, 0, 5) == 'https') {
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        }
        $rtn = curl_exec($ch);
        // if ($rtn === false) {
        //     // 大多由设置等原因引起,一般无法保障后续逻辑正常执行,
        //     // 所以这里触发的是E_USER_ERROR,会终止脚本执行,无法被try...catch捕获,需要用户排查环境、网络等故障
        //     trigger_error("[CURL_" . curl_errno($ch) . "]: " . curl_error($ch), E_USER_ERROR);
        // }
        
        curl_close($ch);
        return $rtn;
    }

免费评分

参与人数 4吾爱币 +4 热心值 +4 收起 理由
Tovgik + 1 + 1 我很赞同!
shane2021 + 1 + 1 我很赞同!
AG9000 + 1 + 1 我很赞同!
HjiaLe02 + 1 + 1 我很赞同!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

Liliright 发表于 2022-8-11 17:42
太厉害了!!!
kiseyzed 发表于 2022-8-11 17:51
7Wen 发表于 2022-8-11 18:06

你看看access_token吧,质疑是很好的。但是建议仔细阅读一下代码,或者参考一下相关文档
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止回复与主题无关非技术内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-29 05:19

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表