收藏
回答

如何解决微信支付中出现【appid和openid不匹配】问题?

@ApiOperation(value = "预支付")
@PostMapping("/wxAppletPay")
public WxPayUnifiedOrderV3Result.JsapiResult  wxAppletPay(PayRequestDTO weChatPayRequest) throws Exception {
    WxPayConfig wxConfig = this.getWxConfig();
    System.out.println(wxConfig.getAppId()+"appid"+weChatPayRequest.getOpenId()+"openid");
    WxPayServiceImpl wxPayServiceApacheHttp = new WxPayServiceImpl();
    wxPayServiceApacheHttp.setConfig(this.getWxConfig());
    WxPayUnifiedOrderV3Request request = new WxPayUnifiedOrderV3Request();
    WxPayUnifiedOrderV3Request.Amount amount = new WxPayUnifiedOrderV3Request.Amount();
    amount.setCurrency("CNY").setTotal(weChatPayRequest.getTotalFee().multiply(new BigDecimal(100)).intValue());
    WxPayUnifiedOrderV3Request.Payer payer = new WxPayUnifiedOrderV3Request.Payer();
    payer.setOpenid(weChatPayRequest.getOpenId());
    WxPayUnifiedOrderV3Request.SceneInfo sceneInfo = new WxPayUnifiedOrderV3Request.SceneInfo();
    sceneInfo.setPayerClientIp("127.0.0.1");
    request.setAmount(amount).setPayer(payer).setOutTradeNo(weChatPayRequest.getOrderNo())
            .setSceneInfo(sceneInfo).setDescription(weChatPayRequest.getBody()).setNotifyUrl("http://ling.l2.ttut.cc/app/wxzf/notify/order");
    WxPayUnifiedOrderV3Result result = wxPayServiceApacheHttp.unifiedOrderV3(TradeTypeEnum.JSAPI, request);
    //WxPayConfig wxConfig =getWxConfig();
    String privateKeyPath = wxConfig.getPrivateKeyPath();
    PrivateKey privateKey =getPrivateKey(privateKeyPath);
    WxPayUnifiedOrderV3Result.JsapiResult payInfo = result.getPayInfo(TradeTypeEnum.JSAPI, wxConfig.getAppId(), wxConfig.getMchId(), privateKey);
    return  payInfo;
}
这是代码 appid是小程序的appid openid是小程序的openid 


回答关注问题邀请回答
收藏

2 个回答

  • 启年
    启年
    08-05

    是微信H5页面里边的支付吗?如果是的话,应该是用户没有授权登录,导致用户在快照页面调用了统一下单接口(此时未获取用户真实openid),导致实际支付的时候openid不一致。

    08-05
    有用
    回复
  • Memory (私信不回复)
    Memory (私信不回复)
    08-05

    A的appid下获取的openid放到了B的appid下来用的,自查吧,对应就不会报错了

    08-05
    有用
    回复
登录 后发表内容