• 获取微信模板消息 发送微信模板消息


    /***
     * 获取微信模板消息id
     * @param $title 标题
     * @return bool 返回id或者false
     */
    function getTemplate_id($title){
        global $_W;
        $access_token = account_weixin_token($_W['account']);
        $url='https://api.weixin.qq.com/cgi-bin/template/get_all_private_template?access_token=';//查询所有模板
        $token=$access_token;
        $data=getData($url.$token);
        $msg=json_decode($data,true);
        foreach($msg['template_list'] as $k=>$v){
            if($v['title']==$title){
                return $v['template_id'];
            }
        }
        return false;
    }
    
    /***
     * 发送微信模板消息
     * @param $template_id 模板id
     * @param $return_url 点击跳转地址
     * @param $openid openid
     * @param $data data数组
     */
    function sendWechatMessgin($template_id,$return_url,$openid,$data){
        global $_W;
        $access_token = account_weixin_token($_W['account']);
        $url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=".$access_token;
        $messgin=array(
            'touser'=>$openid,
            "template_id"=>$template_id,
            "url"=>$return_url,
            "data"=>$data
        );
       return postData($url,json_encode($messgin));
    }
    
    /***
     * get 请求
     * @param $url 请求地址及参数
     * @return mixed 返回结果
     */
    function getData($url)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
        curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        $data = curl_exec($ch);
        curl_close($ch);
        return $data;
    }
    
    /***
     * post 请求
     * @param $url 请求地址
     * @param $data 请求参数
     * @return mixed|string 返回结果
     */
    function postData($url, $data)
    {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $tmpInfo = curl_exec($ch);
        if (curl_errno($ch)) {
            return curl_error($ch);
        }
        curl_close($ch);
        return $tmpInfo;
    }
    
    /****
     * csv下载
     * @param string $name 文件名
     * @param $particular 内容详情
     */
    
    function down_csv($name = '诚美', $particular)
    {
        set_time_limit(0);
        header("Content-Type: text/csv");
        header("Content-Disposition: attachment; filename=" . $name . ".csv");
        header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
        header('Expires:0');
        header('Pragma:public');
        foreach ($particular as $ke => $item) {
            echo $item . "
    ";
        }
        exit;
    }
  • 相关阅读:
    iOS 9正式版开始推送 升级机型非常广泛
    dataWithContentsOfURL报错问题
    Android double输出时保留两位小数
    cornerstone忽略显示.DS_Store文件
    Couldn't open file on client side, trying server side 错误解决
    @SuppressWarnings有什么用处?
    iOS下UITableView的单元格重用逻辑
    根据滑动显隐状态栏的iOS实现
    Runloop之个人理解
    聚合支付概念
  • 原文地址:https://www.cnblogs.com/houdj/p/6813362.html
Copyright © 2020-2023  润新知