search
Homephp教程PHP源码微信模板消息调用

微信模板消息调用

May 27, 2016 am 08:46 AM
php

[PHP]代码

 /*
	 * Curl 请求
	 */
    public function wtw_request($url,$data=null){
        $curl = curl_init(); // 启动一个CURL会话
        curl_setopt($curl, CURLOPT_URL, $url); // 要访问的地址
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); // 对认证证书来源的检查
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
        curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
        if($data != null){
            curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data); // Post提交的数据包
        }
        curl_setopt($curl, CURLOPT_TIMEOUT, 300); // 设置超时限制防止死循环
        curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
        $info = curl_exec($curl); // 执行操作
        if (curl_errno($curl)) {
            echo 'Errno:'.curl_getinfo($curl);//捕抓异常
            dump(curl_getinfo($curl));
        }
        return $info;
    }

    /*
     * 模板消息
     */
    public function templetemsg(){
        //获取ACCESS_TOKEN
        /*string(86) "*****"
         *  string(45) "{"errcode":0,"errmsg":"ok","msgid":201652404}"
         */
        $ACCESS_TOKEN = $this->get_Token();
        $msg_url="https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$ACCESS_TOKEN."";
        $time = date("Y-m-d H:i:s",time());
        $url ="http://www。baidu.com/";   ////这个链接是点击图文 跳转的链接,换行只能用\n 不能用<Br/>
        ////请求包为一个json:
        $msg_json= &#39;{
                        "touser":"oPLOfjqw1fKtdUQPk1vDXCf7K8s0",
                        "template_id":"iZOHjFSa-Ax2UuDlzjJx6IrwUrSvdDhD4TQPnM8kFSY",
                        "url":"&#39;.$url.&#39;",
                        "topcolor":"#FF0000",
                        "data":{
                            "first":{
                                "value":"尊敬的先生:\n恭喜你模板接口调用成功了\n\n",
                                "color":"#000000"
                            },
                            "keyword1":{
                                "value":"模板接口调用测试\n\n",
                                "color":"#000000"
                            },
                            "keyword2":{
                                "value":"&#39;.$time.&#39;\n\n",
                                "color":"#000000"
                            },
                            "remark":{
                                "value":"\n\nThis message is intended only for the use of the inpidual or entity激活成功",
                                "color":"#0099FF"
                            }
                        }
                    }&#39; ;
       $result =  $this->wtw_request($msg_url,$msg_json);
        ///$result = $this->msg_request($msg_url, $msg_json, $header = array());
        dump($result);
    }

                   

                   

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!