liyiorg / weixin-popular

微信SDK JAVA (公众平台、开放平台、 商户平台、 服务商平台)
Apache License 2.0
2.5k stars 1.06k forks source link

PayMchAPI.payUnifiedorder 接口中 unifiedorder.setBody(中文),无法验证签名通过 #20

Closed wcp1230 closed 9 years ago

wcp1230 commented 9 years ago

Unifiedorder unifiedorder = new Unifiedorder(); unifiedorder.setAppid(appid); unifiedorder.setMch_id(mch_id); unifiedorder.setNonce_str(UUID.randomUUID().toString().replace("-", "")); //body中数据设置为中文时,无法验证签名通过 unifiedorder.setBody("商品信息"); unifiedorder.setOut_trade_no("123456"); unifiedorder.setTotal_fee("1");//单位分 unifiedorder.setSpbill_create_ip(request.getRemoteAddr());//IP unifiedorder.setNotify_url("http://mydomain.com/test/notify"); unifiedorder.setTrade_type("JSAPI");//JSAPI,NATIVE,APP,WAP

    UnifiedorderResult unifiedorderResult = PayMchAPI.payUnifiedorder(unifiedorder,key);

    String json = PayUtil.generateMchPayJsRequestJson(unifiedorderResult.getPrepay_id(), appid, key);
liyiorg commented 9 years ago

没有设置 openid 参数

summerwxy commented 9 years ago

底下这段是我运行的代码,我看了一下有设置了 openid 参数不过依然出现 "签名错误" 应该如何解决?

        Unifiedorder unifiedorder = new Unifiedorder();
        unifiedorder.setAppid(appid); 
        unifiedorder.setMch_id(mchid); 
        unifiedorder.setNonce_str(UUID.randomUUID().toString().toString().replace("-", ""));
        unifiedorder.setOpenid(session.openid);
        unifiedorder.setBody("this_is_english");
        unifiedorder.setOut_trade_no("123456");
        unifiedorder.setTotal_fee("1");//单位分
        unifiedorder.setSpbill_create_ip(request.getRemoteAddr());//IP
        unifiedorder.setNotify_url("http://test.mycompany.com/imis/market/notify");
        unifiedorder.setTrade_type("JSAPI");//JSAPI,NATIVE,APP,WAP
        // 统一下单,生成预支付订单
        UnifiedorderResult unifiedorderResult = PayMchAPI.payUnifiedorder(unifiedorder,key);
summerwxy commented 9 years ago

解决了, 我没去商户平台设置API密钥, 设置后正常