admin
2024-06-24 5d3b3b74afd2ac4cf21697fc38367b2f88170e9f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.taoke.autopay.controller;
 
import com.taoke.autopay.entity.KeyOrder;
import com.taoke.autopay.exception.KeyOrderException;
import com.taoke.autopay.factory.OrderFactory;
import com.taoke.autopay.service.KeyOrderService;
import com.taoke.autopay.utils.JsonUtil;
import com.taoke.autopay.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.yeshi.utils.UrlUtils;
 
import javax.annotation.Resource;
import java.io.PrintWriter;
import java.util.Date;
import java.util.List;
 
@Controller
@RequestMapping("webapi")
public class WebApiController {
    Logger logger = LoggerFactory.getLogger(WebApiController.class);
 
    @Resource
    private KeyOrderService keyOrderService;
 
 
    @ResponseBody
    @RequestMapping(value = "submitKey")
    public String submitKey(String  key) {
        if(StringUtil.isNullOrEmpty(key)){
           return JsonUtil.loadFalseResult(0,"请上传key");
        }
       List<String> urllist =  UrlUtils.parseUrlsFromText(key);
       if(urllist.isEmpty()||!urllist.get(0).contains("ur.alipay.com")){
           return JsonUtil.loadFalseResult("支付宝口令不正确");
       }
        try {
            KeyOrder order =   keyOrderService.addKeyOrder(key);
 
            Long uid =  keyOrderService.getCanDistributeUid();
            if(uid!=null){
                KeyOrder orderUpdate=new KeyOrder();
                orderUpdate.setId(order.getId());
                orderUpdate.setDistributeClientUid(uid);
                orderUpdate.setDistributeTime(new Date());
                keyOrderService.update(orderUpdate);
            }
            return JsonUtil.loadTrueResult("");
        } catch (KeyOrderException e) {
            e.printStackTrace();
           return JsonUtil.loadFalseResult(e.getMessage());
        }
    }
 
}