Administrator
2025-04-21 a217652d33c75df23202828000d82d0ca8555ac2
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package com.taoke.autopay.utils;
 
import com.google.gson.Gson;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
 
import java.io.IOException;
import java.net.URLEncoder;
import java.util.Map;
 
/**
 * @author hxh
 * @title: AlipayUtil
 * @description: 支付宝工具类
 * @date 2024/7/23 15:45
 */
public class AlipayOrderUtil {
 
    public static class AlipayOrderTradeInfo{
 
        public final static String STATUS_CANCELED = "BC";
        public final static String STATUS_PAY = "BS";
        public final static String STATUS_NOT_PAY = "BI";
 
        /**
         * bizIdentity : trade20001
         * bizNo : 2024072322001415961410745988
         * bizSuccessDate :
         * goodsQuantity : 1
         * goodsTitle : 抖音电商商家 即时到账--抖音电商-多笔订单6932448966275437765等
         * itemRealAmount : 29.90
         * salesProductCode : QUICK_MSECURITY_PAY
         * status : BC
         */
 
        private String bizIdentity;
        private String bizNo;
        private String bizSuccessDate;
        private int goodsQuantity;
        private String goodsTitle;
        private String itemRealAmount;
        private String salesProductCode;
        // BC: 订单已取消 BS: 订单已支付  BI: 订单未支付
        private String status;
 
        public String getBizIdentity() {
            return bizIdentity;
        }
 
        public void setBizIdentity(String bizIdentity) {
            this.bizIdentity = bizIdentity;
        }
 
        public String getBizNo() {
            return bizNo;
        }
 
        public void setBizNo(String bizNo) {
            this.bizNo = bizNo;
        }
 
        public String getBizSuccessDate() {
            return bizSuccessDate;
        }
 
        public void setBizSuccessDate(String bizSuccessDate) {
            this.bizSuccessDate = bizSuccessDate;
        }
 
        public int getGoodsQuantity() {
            return goodsQuantity;
        }
 
        public void setGoodsQuantity(int goodsQuantity) {
            this.goodsQuantity = goodsQuantity;
        }
 
        public String getGoodsTitle() {
            return goodsTitle;
        }
 
        public void setGoodsTitle(String goodsTitle) {
            this.goodsTitle = goodsTitle;
        }
 
        public String getItemRealAmount() {
            return itemRealAmount;
        }
 
        public void setItemRealAmount(String itemRealAmount) {
            this.itemRealAmount = itemRealAmount;
        }
 
        public String getSalesProductCode() {
            return salesProductCode;
        }
 
        public void setSalesProductCode(String salesProductCode) {
            this.salesProductCode = salesProductCode;
        }
 
        public String getStatus() {
            return status;
        }
 
        public void setStatus(String status) {
            this.status = status;
        }
    }
 
    private static Gson gson=JsonUtil.getSimpleGson();
 
    private static String getLocationUrl(String alipayUrl) throws IOException {
        Connection.Response response =  Jsoup.connect(alipayUrl)
                .userAgent("Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Mobile Safari/537.36")
                .timeout(20000)
                .header("Sec-Ch-Ua","\"Not/A)Brand\";v=\"8\", \"Chromium\";v=\"126\", \"Google Chrome\";v=\"126\"")
                .header("Sec-Ch-Ua-Mobile","?1")
                .header("Sec-Ch-Ua-Platform","\"Android\"")
                .header("Sec-Fetch-Dest","document")
                .header("Sec-Fetch-Mode","navigate")
                .header("Sec-Fetch-Site","none")
                .header("Sec-Fetch-User","?1")
                .followRedirects(false)
                .method(Connection.Method.GET)
                .execute();
        System.out.println(response.statusCode());
 
        if (response.statusCode() == 302 || response.statusCode() == 301) {
            // 获取重定向 URL
            String redirectUrl = response.header("Location");
            System.out.println("Redirect URL: " + redirectUrl);
            return redirectUrl;
        }
        return null;
    }
 
    private static AlipayOrderTradeInfo parseOrderInfo(String biz_no) throws Exception {
       String link = "https://mclient.alipay.com/h5/shareppyprepayconsult.htm?biz_no="+ URLEncoder.encode(biz_no,"UTF-8");
       Connection.Response response =  Jsoup.connect(link)
                .userAgent("Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Mobile Safari/537.36")
                .timeout(20000)
                .header("Sec-Ch-Ua","\"Not/A)Brand\";v=\"8\", \"Chromium\";v=\"126\", \"Google Chrome\";v=\"126\"")
                .header("Sec-Ch-Ua-Mobile","?1")
                .header("Sec-Ch-Ua-Platform","\"Android\"")
                .header("Sec-Fetch-Dest","document")
                .header("Sec-Fetch-Mode","navigate")
                .header("Sec-Fetch-Site","none")
                .header("Sec-Fetch-User","?1")
                .ignoreContentType(true)
                .method(Connection.Method.GET)
                .execute();
        if(response.statusCode()==200){
            String result =  response.body();
            System.out.println(result);
            JSONObject root =  JSONObject.fromObject(result);
            if(root.optBoolean("success")){
                JSONObject data = root.optJSONObject("data");
                if(data!=null){
                    JSONArray tradeInfoList =  data.optJSONArray("tradeInfoList");
                    if(tradeInfoList!=null&&tradeInfoList.size()>0){
                      return  gson.fromJson(tradeInfoList.optJSONObject(0).toString(),AlipayOrderTradeInfo.class);
                    }
                }
            }
            throw new Exception(result);
        }
        throw new Exception("网络请求出错");
    }
 
    public static AlipayOrderTradeInfo getTradeInfo(String url) throws Exception {
         url = getLocationUrl(url);
        if(url!=null){
            Map<String, String> params =  HttpUtil.getPramsFromUrl(url);
            AlipayOrderTradeInfo tradeInfo = parseOrderInfo(params.get("biz_no"));
            return tradeInfo;
        }
        return null;
    }
 
    public static int getOrderType(String orderNoDesc){
        int orderType = Constant.ORDER_TYPE_UNKNOWN;
        if (orderNoDesc.contains("抖音") || orderNoDesc.contains("上海格物致品")) {
            orderType = Constant.ORDER_TYPE_DY;
        } else if (orderNoDesc.contains("快手")) {
            orderType = Constant.ORDER_TYPE_KS;
        }
        return orderType;
    }
 
    public static void main(String[] args) throws Exception {
    String url = getLocationUrl("https://ur.alipay.com/_5MDnsPbo8TAsDNtNB9Tfia");
    if(url!=null){
        Map<String, String> params =  HttpUtil.getPramsFromUrl(url);
        AlipayOrderTradeInfo tradeInfo = parseOrderInfo(params.get("biz_no"));
        System.out.println("");
    }
//        parseOrderInfo("http://www.izxwl.com/admin/index.html");
 
 
    }
 
}