微信公众号开发笔记3--生成带参数二维码

前端开发 作者: 2024-08-26 00:40:01
每次创建二维码ticket需要提供一个开发者自行设定的参数(scene_id),分别介绍临时二维码和永久二维码的创建二维码ticket过程。 临时二维码请求说明 http请求URL https://a
{
    "expire_seconds": 1800,"action_name": "QR_SCENE","action_info": {
        "scene": {
            "scene_id": 100000
        }
    }
}
{
    "action_name": "QR_LIMIT_SCENE",1)"> {
            "scene_id": 1000
        }
    }
}
<?php
//创建二维码
require_once "lib.php";
require_once "downloadfile.php";

肉盾
define("APPID","wxeebd266"); APPID
define("APPSECRET","f6e52");APPSECRET

$token_access_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".APPID."&secret=".APPSECRET; 获取ACCESS_TOKEN请求的URL地址;
$res = file_get_contents($token_access_url);
$result = json_decode($res,true);将获取的返回Json值转换为数组格式
$access_token = $result['access_token'];将获取的access_token保存到临时变量中。*/
//$access_token = "r9IM7qFARYaY7gYOPQLHujhnAkUFS4aqxhMuFao_icIHqgluuCR1Tgnq2S3BIqhlXp1pLY705xsIFhyMZeBAEqIKez9z18ivFT1aLFF40xQV6fJq6ngvwGA0C5ZEcc5UxQv_l4Szr35mrZS01yZUag";
echo $access_tokendefine("ACCESS_TOKEN",$get_msg_url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=".ACCESS_TOKEN;


$rand_area = rand(1,1000$expire_seconds = );

创建临时的ticket
$post_er_array = array(
            "expire_seconds" => $expire_seconds,1)">临时二维码有效时间
            "action_name"=>"QR_SCENE","action_info"=>(
                "scene"=>(
                    "scene_id"=> $expire_seconds
                )
            )
        );
$post_json = json_encode($post_er_array);
$post_json = '{"expire_seconds": 1800,"action_info": {"scene": {"scene_id": 123}}}';


//创建永久的ticket
/*$post_er_array = array(
            "action_name"=>"QR_LIMIT_SCENE","action_info"=>array(
                "scene"=>array(
                    "scene_id"=> $rand_area
                )
            )
        );
$post_json = json_encode($post_er_array);
p($post_json);*/
$post_json = '{"action_name": "QR_LIMIT_SCENE","action_info": {"scene": {"scene_id": 123}}}';

$result = postMsg($get_msg_url,1)">$post_json);

$arr = json_decode($result,1)">true);  获取ticket的值
//p($arr);
$ticket = $arr["ticket"];
p($ticketdefine("TICKET",1)">urlencode());
拉取二维码的URL地址
$get_erweima_url = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=".TICKET;
p($get_erweima_url);  将这里的地址链接直接黏贴到浏览器地址栏访问即可查看到生成的二维码图片


echo downloadfile($get_erweima_url); 开启即可下载生成的二维码图片
View Code
<?function downloadfile($url,1)">$filename="",1)">$timeout=60) {
    $filename = empty($file) ? pathinfo($filename;

    $result = $url);
    $time = date("Y-m-d_H_i_s",1)">time());
    $filename = "./catchFile/".$time.'.'.$result['extension'];
    $filename = "./catchFile/".$time.'.jpg';
    
    $dir = $filename,1)">PATHINFO_DIRNAME);

    !is_dir($dir) && @mkdir($dir,0755,1)">true);

    var_dump($url);
    $url = str_replace(" ","%20",1)">);
    echo "<br />"."asdfasdf"."<br />";
  
    if(function_exists('curl_init')) {
        $ch = curl_init();
        curl_setopt($ch,CURLOPT_URL,1)">);
        $size =  curl_getinfo($ch,CURLINFO_CONTENT_TYPE);
        //var_dump($size);
            curl_setopt(FALSE);  抓取https 链接的设置
            curl_setopt(FALSE);
        curl_setopt($timeoutTRUE);
        $temp = curl_exec($chif(@file_put_contents($temp) && !curl_error()) {
            return ;
        } else {
            return false;
        }
    } {
        $opts = (
            "http"=>(
            "method"=>"GET","header"=>"","timeout"=>)
        );
        $context = stream_context_create($optscopy($file,1)">$context$http_response_header
            $file;
        }
    }
}
View Code
原创声明
本站部分文章基于互联网的整理,我们会把真正“有用/优质”的文章整理提供给各位开发者。本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
本文链接:http://www.jiecseo.com/news/show_68686.html