PHP生成小程序码

PHP生成小程序码

"suiji=hvFlj5",
    "page"=>"pages/index/index"
);

//$dataStr = json_encode($data);
$url="https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=".$access_token;

$result = httpPost($url,json_encode($data));

$base64 = base64_encode($result);
//('data:' . $mime . ';base64,' . $base64);
$strImg = "data:image/png".";base64,".$base64;
echo "";



function httpGet($url){
    $oCurl = curl_init();
    if (stripos($url, "https://") !== FALSE) {
        curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($oCurl, CURLOPT_SSLVERSION, 1);
    }
    curl_setopt($oCurl, CURLOPT_URL, $url);
    curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
    $sContent = curl_exec($oCurl);
    $aStatus = curl_getinfo($oCurl);
    curl_close($oCurl);
    if (intval($aStatus["http_code"]) == 200) {
        return $sContent;
    } else {
        return false;
    }
}

function httpPost($url, $data) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, FALSE);
    curl_setopt($ch, CURLOPT_POST, TRUE);
    if (is_array($data)) {
        foreach ($data as &$value) {
            if (is_string($value) && stripos($value, '@') === 0 && class_exists('CURLFile', FALSE)) {
                $value = new CURLFile(realpath(trim($value, '@')));
            }
        }
    }
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    $data = curl_exec($ch);
    curl_close($ch);
    if ($data) {
        return $data;
    }
    return false;
}


?>

你可能感兴趣的:(PHP)