欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2022-06-04 14:56:31
...
怎样获取微信开放平台的预授权码?是通过填写的哪个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格式提交