Git Product home page Git Product logo

weixin-pay's Introduction

weixin-pay

微信支付最新版 java 实现

实现微信支付 Native 扫码支付

支付场景在 微信支付文档




步骤:

1 生成二维码链接地址

String payNativeUrl = PayUtils.generateMchPayNativeRequestURL(productId);

然后可以通过jqueyQrcode的插件,在页面上生成二维码

2 扫码二维码后微信发送的请求处理

封装输入信息

PayNativeInput payNativeInput = PayUtils.convertRequest(request.getInputStream());

验证合法性

			
boolean validate = PayUtils.validateAppSignature(payNativeInput);

if(!validate){
	return null;
}

封装商品信息

			
PayPackage payPackage = new PayPackage();

payPackage.setAppid(payNativeInput.getAppid());
payPackage.setAttach("test");
payPackage.setBody("product");
payPackage.setNonce_str(payNativeInput.getNonce_str());
payPackage.setMch_id(payNativeInput.getMch_id());
payPackage.setOpenid(payNativeInput.getOpenid());
payPackage.setOut_trade_no(UUID.randomUUID().toString().replace("-", ""));
payPackage.setProduct_id(payNativeInput.getProduct_id());
payPackage.setSpbill_create_ip("127.0.0.1");
payPackage.setTotal_fee("1");
payPackage.setTrade_type("NATIVE");

发送统一下单请求

	String replyXml = PayUtils.generatePayNativeReplyXML(payPackage);

3 支付成功回调

PayCallbackNotify payCallbackNotify = PayUtils.payCallbackNotify(request.getInputStream());
if(payCallbackNotify.isPaySuccess()){
	String content = PayUtils.generatePaySuccessReplyXML();
	return content;
}
			

系统依赖jar包

compile 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.4.0'
compile 'org.apache.httpcomponents:httpclient:4.4'
compile 'log4j:log4j:1.2.17'
compile 'commons-io:commons-io:2.3'
compile 'commons-beanutils:commons-beanutils:1.9.2'
	

weixin-pay's People

Contributors

louiseliu avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.