技术汇总:第十四章:电脑端生成支付宝二维码支付
支付宝支付
第一步:alipay.properties
alipay_url=https://openapi.alipay.com/gateway.do
#app的id
app_id=2018020102122556
#私钥
app_private_key=MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCdQeknhM2rhiGAH6V0ljxn3rAWIdzduTEQuteTfwjnZtvMhQPuuN1b/88D5yMuaZhZNFeUdWb+SmtP9DAzAWWgnT13T0YhJcxP6txm7JBRrjadCRt+LOFxPiPQk5t9fH7yXjw9i4uMDsNJeTncrVZ/AZYrk0ESC9anJR8XeuBc3HE8T4fqlKKl35jlumIWrPbPNQhKGXaGcOnpiaXO9qYYUSP/tnrjNYXHOso0yBs4YTl+LLX2TJ12p3n/oX6HnL4zQgtN5k4QasHP7CIig1ngcVQGfWsMm4djI9KXNXvGLQPfMQEmyb71mM5OCdl1MtAc6OaIAymhSv2hOLNIuyodAgMBAAECggEAe05/P5mGm4QlKI2n8u8KlneqovASe1kG/BNFjkYB+VBR8OAr4TfbepPvAyRuFap+5xN/yMz14VcBJkRWtufVhEdHNxJV7w/wUIncIGhGEYYFFMVbZWhTrbQH6TiUp6TC9dCmc6vD1CKPRkFj+YGBXT0lPy3LzBa0TYNyCbszyhthrgkpuFYbB0R93IPvvBh5NJFXQytwNb2oVopC9AQWviqnZUZcT0eJ087dQ1WLPa6blBD8DP1PUq0Ldr6pgKfObFxIj8+87DlJznRfdEsbqZlS7jagdw5tLr71WJpctIGPqKpgvajfePP/lj3eY82BKQB+aTw0zmAiB05Yes4LgQKBgQDq3EiQR8J1MEN2rpiLt1WvDYYvKVUgOY7Od//fRPgaMBstbe4TzGBpR8E+z267bHAWLaWtHkfX6muFHn1x68ozEUWk/nZq0smWnuPdcy4E7Itbk36W2FF/rOZB7j5ddlC9byrxDSNgcf9/FA/CU+i5KVQpLYfsk2dvwomvu0aFVQKBgQCraXpxzMmsBx4127LsZDO5bxfxb6nqzyK4NPe0VaGiRg8oaCWczcLz1J5iRqC9Qe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ipay/callback/return
#异步地址需要外网可以访问(暂时没有写)
notify_payment_url=http://60.205.215.91/alipay/callback/notify
第二步:PayController
package com.macro.mall.portal.controller;
import com.alibaba.fastjson.JSON;
import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.internal.util.AlipaySignature;
import com.alipay.api.request.AlipayTradePagePayRequest;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.OmsOrderItem;
import com.macro.mall.model.PaymentInfo;
import com.macro.mall.portal.config.AlipayConfig;
import com.macro.mall.portal.service.OmsPortalOrderService;
import com.macro.mall.portal.service.PaymentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
/**
* 支付管理
*/
@Controller
@Api(tags = "PayController", description = "支付管理")
@RequestMapping("/member/pay")
public class PayController {
@Autowired
private PaymentService paymentService;
@Autowired
private OmsPortalOrderService omsPortalOrderService;
@Autowired
AlipayClient alipayClient;
@ApiOperation("去支付")
@RequestMapping(value = "/alipay/submit", method = RequestMethod.GET)
@ResponseBody
public String goToPay( String orderSn, BigDecimal totalAmount) {
//根据订单编号获取订单详情信息
OmsOrderItem omsOrderItem =omsPortalOrderService.getOrderByOrderSn(orderSn);
//获取商品名称
String productName = omsOrderItem.getProductName();
//创建PC场景下单并支付请求对象
AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();//创建API对应的request
//设置同步返回地址,HTTP/HTTPS开头字符串
alipayRequest.setReturnUrl(AlipayConfig.return_payment_url);
//支付宝服务器主动通知商户服务器里指定的页面http/https路径。
alipayRequest.setNotifyUrl(AlipayConfig.notify_payment_url);//在公共参数中设置回跳和通知地址
Map<String,String> requestMap = new HashMap<>();
requestMap.put("out_trade_no",orderSn);//订单编号
requestMap.put("product_code","FAST_INSTANT_TRADE_PAY");//产品交易码
requestMap.put("total_amount","0.01");//实际付款金额
requestMap.put("subject",productName);//商品名称
//填充业务参数
alipayRequest.setBizContent(JSON.toJSONString(requestMap));
String form