Browse Source

微信公众号登录

lyhzzz 2 năm trước cách đây
mục cha
commit
08cb4be514

+ 7 - 0
pom.xml

@@ -111,6 +111,13 @@
             <version>1.14.0</version>
             <version>1.14.0</version>
         </dependency>
         </dependency>
 
 
+        <dependency>
+            <groupId>com.dtflys.forest</groupId>
+            <artifactId>forest-spring-boot-starter</artifactId>
+            <version>1.5.24</version>
+        </dependency>
+
+
     </dependencies>
     </dependencies>
 
 
     <build>
     <build>

+ 0 - 21
src/main/java/com/fdkankan/pay/controller/AliConfigController.java

@@ -1,21 +0,0 @@
-package com.fdkankan.pay.controller;
-
-
-import org.springframework.web.bind.annotation.RequestMapping;
-
-import org.springframework.web.bind.annotation.RestController;
-
-/**
- * <p>
- *  前端控制器
- * </p>
- *
- * @author 
- * @since 2023-04-14
- */
-@RestController
-@RequestMapping("/pay/aliConfig")
-public class AliConfigController {
-
-}
-

+ 32 - 0
src/main/java/com/fdkankan/pay/controller/PayController.java

@@ -1,18 +1,50 @@
 package com.fdkankan.pay.controller;
 package com.fdkankan.pay.controller;
 
 
+import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.pay.common.ResultCode;
 import com.fdkankan.pay.common.ResultData;
 import com.fdkankan.pay.common.ResultData;
 import com.fdkankan.pay.entity.Order;
 import com.fdkankan.pay.entity.Order;
+import com.fdkankan.pay.entity.WxConfig;
+import com.fdkankan.pay.exception.BusinessException;
+import com.fdkankan.pay.httpClient.client.WxClient;
+import com.fdkankan.pay.service.IOrderService;
+import com.fdkankan.pay.service.IWxConfigService;
 import com.fdkankan.pay.service.impl.PayOrderService;
 import com.fdkankan.pay.service.impl.PayOrderService;
 import com.fdkankan.pay.util.UrlUtils;
 import com.fdkankan.pay.util.UrlUtils;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
 
 
 @RestController
 @RestController
 @RequestMapping("/service/pay")
 @RequestMapping("/service/pay")
+@Slf4j
 public class PayController extends BaseController {
 public class PayController extends BaseController {
 
 
     @Autowired
     @Autowired
     PayOrderService payOrderService;
     PayOrderService payOrderService;
+    @Autowired
+    WxClient wxClient;
+    @Autowired
+    IOrderService orderService;
+    @Autowired
+    IWxConfigService wxConfigService;
+
+    @GetMapping("/wxLogin")
+    public ResultData wxLogin(@RequestParam(required = false) String code,@RequestParam(required = false) String orderSn){
+        log.info("wx-login----orderSn:{},code:{}",orderSn,code);
+        Order order = orderService.getByOrderSn(orderSn);
+        if(order == null ){
+            throw new BusinessException(ResultCode.ORDER_NOT_EXIST);
+        }
+        WxConfig wxConfig = wxConfigService.getByServeId(order.getServeId());
+        if(wxConfig == null){
+            throw new BusinessException(ResultCode.WX_CONFIG_NOT);
+        }
+        JSONObject object = wxClient.getToken(wxConfig.getAppid(), wxConfig.getSecret(), code);
+        return ResultData.ok(object);
+    }
+
+
 
 
     @PostMapping(value = "/openPay")
     @PostMapping(value = "/openPay")
     public ResultData openPay(@RequestBody Order param) throws Exception {
     public ResultData openPay(@RequestBody Order param) throws Exception {

+ 1 - 1
src/main/java/com/fdkankan/pay/entity/Order.java

@@ -61,7 +61,7 @@ public class Order implements Serializable {
     private BigDecimal orderMoney;
     private BigDecimal orderMoney;
 
 
     /**
     /**
-     * 0微信h5,1微信jsapi, 2支付宝,3paypal
+     * 0微信h5,1微信jsapi,2,微信扫码支付,3支付宝扫码,4支付宝h5
      */
      */
     @TableField("pay_type")
     @TableField("pay_type")
     private Integer payType;
     private Integer payType;

+ 37 - 0
src/main/java/com/fdkankan/pay/httpClient/client/WxClient.java

@@ -0,0 +1,37 @@
+package com.fdkankan.pay.httpClient.client;
+
+import com.alibaba.fastjson.JSONObject;
+import com.dtflys.forest.annotation.*;
+import org.springframework.web.bind.annotation.RequestHeader;
+
+/**
+ * 获取,调用4dkk服务
+ */
+@BaseRequest(sslProtocol = "TLS")
+public interface WxClient {
+
+    /**
+     * 获取 access_token
+     */
+    @Get("https://open.weixin.qq.com/connect/oauth2/authorize?" +
+            "appid={appid}&redirect_uri={redirectUri}&response_type=code&scope=snsapi_base&state=123#wechat_redirect")
+    JSONObject getCode(@Query("appid") String app_id, @Query("redirectUri") String redirectUri);
+    /**
+     * 获取 access_token
+     */
+    @Get("https://api.weixin.qq.com/sns/oauth2/access_token?appid={appid}&secret={secret}&code={code}&grant_type=authorization_code")
+    JSONObject getToken(@Query("appid") String app_id, @Query("secret") String app_secret,@Query("code") String code);
+
+    /**
+     * 申请账单
+     */
+    @Get(value = "https://api.mch.weixin.qq.com/v3/bill/fundflowbill",headers = {
+            "Accept:application/json",
+            "Content-Type: application/json"
+    })
+    JSONObject tradeBill(@Query("bill_date") String bill_date,
+                         @Query("bill_type") String bill_type,
+                         @Query("tar_type") String tar_type,
+                         @Header("Authorization") String authorization);
+
+}