1. 程式人生 > >生成小程式碼的範例

生成小程式碼的範例

public function wxappqrcode($uid){

        global $_W;
        $account_api = WeAccount::create();
        $token = $account_api->getAccessToken();      
      	
        $url = "https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=".$token;
        $params = array();
        $params['scene'] = "user_id=".$uid;
        $params['width'] = 300;
        $params['page'] = "hc_answer/pages/index/index";
      
        $result = ihttp_post($url, json_encode($params));
        $res = json_decode($result['content'],true);

        if($res['errcode'] == '41030'){
            return 'https://we10.66bbn.com/addons/hc_answer/public/qrcode.jpg';
        }else{
            $dir = IA_ROOT.'/addons/hc_answer/upload/';
            if(!file_exists($dir)){
                mkdir($dir,0777,true);
            }
            file_put_contents(IA_ROOT.'/addons/hc_answer/upload/'.$uid.'.jpg',$result['content']);
            return $_W['siteroot'].'addons/hc_answer/upload/'.$uid.'.jpg'; 
        }
    }