int(41002) ["errmsg"]=> string(13) "appid missing" } 代码部分:">
当前位置:Gxlcms > PHP教程 > 如何获取微信开放平台的预授权码?

如何获取微信开放平台的预授权码?

时间:2021-07-01 10:21:17 帮助过:8人阅读

怎样获取微信开放平台的预授权码?是通过填写的哪个url进入获取的?

报错:

array(2) { ["errcode"]=> int(41002) ["errmsg"]=> string(13) "appid missing" } 

代码部分:

    $ch = curl_init();
    $url="https://api.weixin.qq.com/cgi-bin/component/api_component_token";
    $data=array(
        'component_appid'=>$APPID,
        'component_appsecret'=>$SECRET,
        'component_verify_ticket'=>$ticket['ticket']
    );
    $data=http_build_query($data);
    //var_dump($data);

    $ch = curl_init();//打开
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    $response  = curl_exec($ch);
    curl_close($ch);//关闭
    $result = json_decode($response,true);

回复内容:

怎样获取微信开放平台的预授权码?是通过填写的哪个url进入获取的?

报错:

array(2) { ["errcode"]=> int(41002) ["errmsg"]=> string(13) "appid missing" } 

代码部分:

    $ch = curl_init();
    $url="https://api.weixin.qq.com/cgi-bin/component/api_component_token";
    $data=array(
        'component_appid'=>$APPID,
        'component_appsecret'=>$SECRET,
        'component_verify_ticket'=>$ticket['ticket']
    );
    $data=http_build_query($data);
    //var_dump($data);

    $ch = curl_init();//打开
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    $response  = curl_exec($ch);
    curl_close($ch);//关闭
    $result = json_decode($response,true);

appid missing
你没有定义$APPID变量

是$data传值的问题,已经解决了

遇到同样问题,传参的时候是json格式 之前直接post 3个参数一直{"errcode":41002,"errmsg":"appid missing"} 这个错误。json_encode(['component_appid'=>,'component_appsecret'=>,'component_verify_ticket'=>]);

$data 要以JSON格式提交

人气教程排行