zoukankan      html  css  js  c++  java
  • 微信生成二维码

    本人小菜鸟一仅仅。为了自我学习和交流PHP(jquery,linux,lamp,shell,javascript,server)等一系列的知识,小菜鸟创建了一个群。希望光临本博客的人能够进来交流。寻求共同发展。

    搭建平台。本人博客也有很多的技术文档。希望能够为你提供一些帮助。

    QQ群:   191848169               QQ:450225664



    //生成带參数的暂时二维码 用于绑定微信号
    
    $memcache = new Memcache;
    $memcache->addServer('127.0.0.1',11211);
    //检測是否有反复
    do{
    	$rand_code = rand(20000,30000);
    }while($memcache->get($rand_code));
    //将user_id 存入memcache 缓存
    $memcache->set($rand_code,$_SESSION['user_id'],3600);
    
    //获得access_token;
    // $resultd =file_get_contents('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wxdafc634908061c97&secret=584d57925a832e76676adeabb785dce8');
    // $resultd = json_decode($resultd);
    // $access_token = $resultd->access_token;
    $access_token = WXBaseFun::getAccessToken();
    //获得ticket
    $qrcode = '{"expire_seconds": 1800, "action_name": "QR_SCENE", "action_info": {"scene": {"scene_id": '.$rand_code.'}}}';
    $url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=$access_token";
    $resulstd = https_post($url,$qrcode);
    $jsoninfo = json_decode($resulstd,true);
    $ticket = $jsoninfo['ticket'];
    //下载二维码图片
    $urls = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=".urlencode($ticket);
    $imageinfo = downloadimagefromweixin($urls);
    $filename = time().'_qrcode.jpg';
    $local_file = fopen('qrcode/'.$filename, 'w');
    if(false !==$local_file){
    	if(false !==fwrite($local_file, $imageinfo['body'])){
    		fclose($local_file);
    	}
    }
    //分配生成的图片
    $smarty->assign('code_img',$filename);
    
    //生成带參数的二维码结束

  • 相关阅读:
    Codeforces 1244C The Football Season (解方程)
    BZOJ 2006 [NOI2010]超级钢琴(ST表+堆)
    51Nod 1681 公共祖先(dfs+树状数组/主席树)
    CF 1076E Vasya and a Tree(dfs+树状数组)
    CF 1076 D Edge Deletion(最短路径+bfs)
    CF Gym 102059I Game on Plane(sg函数)
    POJ 2311 Cutting Game(二维sg)
    POJ 2960 S-Nim(SG函数模板题)
    CF Gym 102059F Fake Plastic Trees
    CF Gym 102059H Fractions(思维题)
  • 原文地址:https://www.cnblogs.com/bhlsheji/p/5066313.html
Copyright © 2011-2022 走看看