spring boot 下支付寶的開箱既用環(huán)境
更新時間:2017年10月31日 16:26:35 投稿:mrr
這篇文章主要介紹了spring boot 下支付寶的開箱既用環(huán)境包括使用場景和使用技巧,非常不錯,具有參考借鑒價值,需要的朋友參考下吧
sdk-alipay
spring boot下支付寶的開箱既用環(huán)境
使用場景
spring boot應用中需要接入支付寶
開始使用
pom.xml中引入依賴
<dependency> <groupId>net.guerlab</groupId> <artifactId>sdk-alipay-starter</artifactId> <version>1.0.3</version> </dependency>
bootstrap.yml中增加配置
sdk: alipay: dev: true/false #默認false,為true表示使用沙箱環(huán)境 sign-type: RSA2 #簽名算法 app-id: #應用ID private-key: #應用私鑰 alipay-public-key: #支付寶公鑰
增加控制器實現(xiàn)
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import com.alibaba.fastjson.JSONObject; import com.alipay.api.AlipayClient; import com.alipay.api.request.AlipayTradeAppPayRequest; import com.alipay.api.request.AlipayTradePagePayRequest; import com.alipay.api.request.AlipayTradeWapPayRequest; import net.guerlab.sdk.alipay.controller.AlipayAbstractController; @RequestMapping("/pay/alipay") public class AlipayController extends AlipayAbstractController { @Autowired private AlipayClient client;//支付寶請求sdk客戶端 /** * 支付請求 */ @GetMapping("/app/{orderId}") public String app( @PathVariable Long orderId, HttpServletResponse httpResponse) { JSONObject data = new JSONObject(); data.put("out_trade_no", "201701010000001234"); //商戶訂單號 data.put("product_code", "QUICK_MSECURITY_PAY"); //產品碼, APP支付 QUICK_MSECURITY_PAY, PC支付 FAST_INSTANT_TRADE_PAY, 移動H5支付 QUICK_WAP_PAY data.put("total_amount", "0.01"); //訂單金額 data.put("subject", "測試訂單"); //訂單標題 //APP支付 AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest(); //PC支付 //AlipayTradePagePayRequest request = new AlipayTradePagePayRequest(); //移動H5支付 //AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); request.setNotifyUrl("http://demo/pay/alipay/notify/1"); //異步通知地址 request.setBizContent(data.toJSONString()); //業(yè)務參數(shù) return client.sdkExecute(request).getBody(); } @PostMapping("/notify/{orderId}") public String notify( @PathVariable Long orderId, HttpServletRequest request) { if (!notify0(request.getParameterMap())) { //這里處理驗簽失敗 } request.getParameter("trade_no");//獲取請求參數(shù)中的商戶訂單號 return "success"; } }
總結
以上所述是小編給大家介紹的spring boot 下支付寶的開箱既用環(huán)境,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
相關文章
Spring Boot 深入分析AutoConfigurationImportFilter自動化條件
這篇文章主要分析了Spring Boot AutoConfigurationImportFilter自動化條件配置源碼,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習吧2022-07-07Spring中使用copyProperties方法進行對象之間的屬性賦值詳解
這篇文章主要介紹了Spring中使用copyProperties方法進行對象之間的屬性賦值詳解,使用org.springframework.beans.BeanUtils.copyProperties方法進行對象之間屬性的賦值,避免通過get、set方法一個一個屬性的賦值,需要的朋友可以參考下2023-12-12