统一支付接口中,缺少必填参数openid!trade_type为JSAPI时,openid为必填参数!
程序员文章站
2022-05-18 15:27:45
...
$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框架,你可以参考下