在调用“JSAPI下单”接口
/v3/pay/transactions/jsapi 时响应内容里提示:“输入源“/appid”映射到字段“公众号I (truncated...)”
我确认我填写的appid是小程序的不是公众号的,使用的是官方的wechatpay-apiv3/wechatpay-php sdk,核心代码如下:
// 获取预支付id
public static function orderInfo($p){
$url = 'https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi';
// $url = '/v3/pay/transactions/jsapi';
$appId = Config::WxAppId;
$mchId = Config::WxMchId;
$mchName = Config::WxMchName;
$serial_no = Config::WxPayCartNo;
$orderNo = dechex(time()) . rand(1000, 9999);
$notify_url = Config::Host . Config::BasePath . '/wechat/payNotify';
$score = $p['score'];
$openId = '我自己的openid';
// 从本地文件中加载「商户API私钥」,「商户API私钥」会用来生成请求的签名
$merchantPrivateKey = file_get_contents(SS_PLUGIN_APP_DIR.'/certs/apiclient_key.pem');
$merchantPrivateKeyInstance = Rsa::from($merchantPrivateKey, Rsa::KEY_TYPE_PRIVATE);
// 从本地文件中加载「微信支付平台证书」,用来验证微信支付应答的签名
$platformCertificate = file_get_contents(SS_PLUGIN_APP_DIR.'/certs/apiclient_cert.pem');
$platformPublicKeyInstance = Rsa::from($platformCertificate, Rsa::KEY_TYPE_PUBLIC);
// 从「微信支付平台证书」中获取「证书序列号」
$platformCertificateSerial = PemUtil::parseCertificateSerialNo($platformCertificate);
// 构造一个 APIv3 客户端实例
$instance = Builder::factory([
'mchid' => $mchId,
'serial' => $serial_no,
'privateKey' => $merchantPrivateKeyInstance,
'certs' => [
$platformCertificateSerial => $platformPublicKeyInstance,
],
]);
$data = array(
"appid" => $appId,
"mchid" => $mchId,
"description" => "$mchName-积分充值-$score",
"out_trade_no" => $orderNo,
"time_expire" => time() + 600,
"attach" => "自定义数据说明",
"notify_url" => $notify_url,
"amount" => array(
"total" => $p['price'],
"currency" => "CNY"
),
"payer" => array(
"openid" => $openId
)
);
try{
$rep = $instance->chain($url)->post($data)->getBody();
return json_decode($rep);
}catch(Exception $e){
$code = $e->getCode();
return array('code' => $code, 'rep' => $e->getMessage(), 'req' => $data);
}
}
// $e->getMessage():
'Client error: `POST https://api.mch.weixin.qq.com/v3/pay/transactions/jsapi` resulted in a `400 Bad Request` response:\n{"code":"PARAM_ERROR","detail":{"location":null,"value":""},"message":"输入源“/appid”映射到字段“公众号I (truncated...)\n'
看起来是appid参数传的不对,打印日志看下请求参数,还有要打印完整报错出来看看
总而言之,微信出错概率非常大,官方也没有明确说明,感觉就是可垃圾,弄得对接困难有啥意义
博主解决了吗 我也是这个问题