Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.9.4.beta 支付 createOrder 签名错误 #424

Closed
gtyang opened this issue Jan 14, 2018 · 4 comments
Closed

2.9.4.beta 支付 createOrder 签名错误 #424

gtyang opened this issue Jan 14, 2018 · 4 comments

Comments

@gtyang
Copy link

gtyang commented Jan 14, 2018

我做了一个支付createOrder单元测试,使用的版本是 2.9.4-beta,代码如下:

@SpringBootTest(classes=WxMpApplication.class)
@RunWith(SpringRunner.class)
public class SignTest {

	private static final Logger logger = LoggerFactory.getLogger(PayController.class);

	@Resource(name = "wxPayService")
	private WxPayService wxPayService;

	@Test
	public void test() {
		try {
			WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
			orderRequest.setBody("Test-Order-001212348");
			orderRequest.setOutTradeNo("test-order-2808");
			orderRequest.setTotalFee(BaseWxPayRequest.yuanToFen("0.01"));//元转成分
			orderRequest.setOpenid("oEKyh1KN2lJZKTplZRjZ6Eu6jpc4");
			orderRequest.setSpbillCreateIp("127.0.0.1");
			
			orderRequest.setTimeStart("20180111091011");
			orderRequest.setTimeExpire("20180111111011");
			
			orderRequest.setNotifyURL("http://api.alpha.com.cn/pay/notify");
			orderRequest.setTradeType("JSAPI");

			WxPayUnifiedOrderResult result = wxPayService.createOrder(orderRequest);

			logger.error(result.getSign());
			assertTrue(result.getSign() != null);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

抛出的异常如下:

2018-01-14 23:03:05.634 ERROR 34893 --- [ main] c.g.b.w.b.r.WxPayUnifiedOrderResult : 结果业务代码异常,返回结果:{return_msg=签名错误, return_code=FAIL}, 返回代码:FAIL,返回信息:签名错误

@gtyang gtyang changed the title 2.9.4-beta 签名错误 2.9.4-beta 支付 createOrder 签名错误 Jan 14, 2018
@gtyang gtyang changed the title 2.9.4-beta 支付 createOrder 签名错误 2.9.4.beta 支付 createOrder 签名错误 Jan 15, 2018
@binarywang
Copy link
Owner

请认真调试下,看看你的代码哪里出了问题

@gtyang
Copy link
Author

gtyang commented Jan 15, 2018

request正常设置了啊,发送的请求 xml 是

<xml>
  <appid>wx8ce443**********</appid>
  <mch_id>*********</mch_id>
  <nonce_str>1516009722088</nonce_str>
  <sign>288134A51005EFAE4FBB308C0E8CB192</sign>
  <body>Test-Order-001212348</body>
  <out_trade_no>test-order-2808</out_trade_no>
  <total_fee>1</total_fee>
  <spbill_create_ip>127.0.0.1</spbill_create_ip>
  <time_start>20180111091011</time_start>
  <time_expire>20180111111011</time_expire>
  <notify_url>http://api.alpha.com.cn/pay/notify</notify_url>
  <trade_type>JSAPI</trade_type>
  <openid>oEKyh1KN2lJZKTplZRjZ6Eu6jpc4</openid>
</xml>

这个数据用微信的签名核验工具生成的签名和程序生成的签名不一样:

#4.校验结果:
原sign值:288134A51005EFAE4FBB308C0E8CB192
新sign值:5F599381E3033C787A48769197EC47D5

@binarywang
Copy link
Owner

自己一步步调试源码看看

@gtyang
Copy link
Author

gtyang commented Jan 15, 2018

找到问题了,是signKey设置有问题。

@gtyang gtyang closed this as completed Jan 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants