当前位置:Gxlcms > PHP教程 > 统一支付接口中,缺少必填参数openid!trade_type为JSAPI时,openid为必填参数!

统一支付接口中,缺少必填参数openid!trade_type为JSAPI时,openid为必填参数!

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

    $jsApi = new JsApi_pub();
    //=========步骤1:网页授权获取用户openid============
    //通过code获得openid
 if (!isset($_GET['code']))
{
     //触发微信返回code码
     $url = $jsApi->createOauthUrlForCode(WxPayConf_pub::JS_API_CALL_URL);
     Header("Location: $url"); 
}else{
    //获取code码,以获取openid
     $code = $_GET['code'];
    $jsApi->setCode($code);
    $openid = $jsApi->getOpenId();
    echo $openid;   这里获取不到
    echo "
"; } $unifiedOrder = new UnifiedOrder_pub(); $unifiedOrder->setParameter("openid","$openid");//商品描述 $unifiedOrder->setParameter("body","微信支付测试");//商品描述

回复内容:

    $jsApi = new JsApi_pub();
    //=========步骤1:网页授权获取用户openid============
    //通过code获得openid
 if (!isset($_GET['code']))
{
     //触发微信返回code码
     $url = $jsApi->createOauthUrlForCode(WxPayConf_pub::JS_API_CALL_URL);
     Header("Location: $url"); 
}else{
    //获取code码,以获取openid
     $code = $_GET['code'];
    $jsApi->setCode($code);
    $openid = $jsApi->getOpenId();
    echo $openid;   这里获取不到
    echo "
"; } $unifiedOrder = new UnifiedOrder_pub(); $unifiedOrder->setParameter("openid","$openid");//商品描述 $unifiedOrder->setParameter("body","微信支付测试");//商品描述

BeeCloud对各种支付渠道的API做了封装,提供了一套REST API框架,你可以参考下

人气教程排行