1.引入jar包
<dependency>
<groupId>com.github.javen205</groupId>
<artifactId>IJPay-WxPay</artifactId>
<version>2.7.2</version>
</dependency>
2. 开始调用微信官方支付接口
/**
* 公众号支付
*/
@RequestMapping(value = "/webPay", method = {RequestMethod.POST, RequestMethod.GET})
@ResponseBody
public AjaxResult webPay(@RequestBody byte[] req) {
JSONObject json = JSONObject.parseObject(new String(req, Charset.forName("UTF-8")));
System.out.println("请求参数"+json);
// openId,采用 网页授权获取 access_token API:SnsAccessTokenApi获取
JSONObject request = JSONObject.parseObject(new String(req, Charset.forName("UTF-8")));
String openId = request.getString("openid");
if(StringUtils.isEmpty(openId)){
return AjaxResult.error("支付异常,请联系管理员");
}