xuhy
2025-01-09 712f70b2936079a131ecb1e63c6d337171618cad
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
package com.stylefeng.guns.modular.api;
 
import com.alibaba.fastjson.JSONObject;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.base.tips.ErrorTip;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.core.shiro.ShiroUser;
import com.stylefeng.guns.core.util.JwtTokenUtil;
import com.stylefeng.guns.core.util.PaymentTypeEnum;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.cloudPayment.example.BalanceAcctExample;
import com.stylefeng.guns.modular.cloudPayment.example.DepositExample;
import com.stylefeng.guns.modular.cloudPayment.example.MchApplicationExample;
import com.stylefeng.guns.modular.cloudPayment.example.RefundExample;
import com.stylefeng.guns.modular.cloudPayment.req.BalanceAcctReq;
import com.stylefeng.guns.modular.cloudPayment.req.DepositReq;
import com.stylefeng.guns.modular.system.dao.UserMapper;
import com.stylefeng.guns.modular.system.model.User;
import com.stylefeng.guns.modular.system.service.ITCompanyService;
import com.stylefeng.guns.modular.system.service.ITDriverService;
import com.unionpay.upyzt.exception.UpyztException;
import com.unionpay.upyzt.resp.BalanceAcctListResp;
import com.unionpay.upyzt.resp.BalanceAcctResp;
import com.unionpay.upyzt.resp.DepositResp;
import com.unionpay.upyzt.resp.MchApplicationResp;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.HashedCredentialsMatcher;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.apache.shiro.util.ByteSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
 
/**
 * 接口控制器提供
 *
 * @author stylefeng
 * @Date 2018/7/20 23:39
 */
@RestController
@RequestMapping("/gunsApi")
public class ApiController extends BaseController {
 
    @Autowired
    private UserMapper userMapper;
 
    @Resource
    private ITCompanyService companyMapper;
 
    @Autowired
    private ITDriverService driverService;
 
    /**
     * api登录接口,通过账号密码获取token
     */
    @RequestMapping("/auth")
    public Object auth(@RequestParam("username") String username,
                       @RequestParam("password") String password) {
 
        //封装请求账号密码为shiro可验证的token
        UsernamePasswordToken usernamePasswordToken = new UsernamePasswordToken(username, password.toCharArray());
 
        //获取数据库中的账号密码,准备比对
        User user = userMapper.getByAccount(username);
 
        String credentials = user.getPassword();
        String salt = user.getSalt();
        ByteSource credentialsSalt = new Md5Hash(salt);
        SimpleAuthenticationInfo simpleAuthenticationInfo = new SimpleAuthenticationInfo(
                new ShiroUser(), credentials, credentialsSalt, "");
 
        //校验用户账号密码
        HashedCredentialsMatcher md5CredentialsMatcher = new HashedCredentialsMatcher();
        md5CredentialsMatcher.setHashAlgorithmName(ShiroKit.hashAlgorithmName);
        md5CredentialsMatcher.setHashIterations(ShiroKit.hashIterations);
        boolean passwordTrueFlag = md5CredentialsMatcher.doCredentialsMatch(
                usernamePasswordToken, simpleAuthenticationInfo);
 
        if (passwordTrueFlag) {
            HashMap<String, Object> result = new HashMap<>();
            result.put("token", JwtTokenUtil.generateToken(String.valueOf(user.getId())));
            return result;
        } else {
            return new ErrorTip(500, "账号密码错误!");
        }
    }
    @GetMapping("/auth1")
    public Object auth1( String number) {
//        6207982267191357985
        try {
            BalanceAcctReq balanceAcctReq = new BalanceAcctReq();
            balanceAcctReq.setMchId(number);
            BalanceAcctListResp balanceAcctListResp = BalanceAcctExample.retrieveByUserId(balanceAcctReq);
            return balanceAcctListResp;
        } catch (UpyztException e) {
            e.printStackTrace();
            return number;
        }
 
 
    }
    @GetMapping("/auth11")
    public Object auth11( String number) {
//        6207982267191357985
        try {
            BalanceAcctReq balanceAcctReq = new BalanceAcctReq();
            balanceAcctReq.setCusId(number);
            BalanceAcctListResp balanceAcctListResp = BalanceAcctExample.retrieveByUserId(balanceAcctReq);
            return balanceAcctListResp;
        } catch (UpyztException e) {
            e.printStackTrace();
            return number;
        }
    }
 
    @GetMapping("/auth2")
    public Object auth2() {
        try {
            companyMapper.updateMoney();
            return "ok";
        }catch (Exception e){
            e.printStackTrace();
            return e;
        }
 
    }
 
    @GetMapping(value = "/auth22")
//    @ApiOperation(value = "支付充值查询", tags = {"支付充值查询"}, notes = "")
//    @ApiImplicitParams({
//            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
//    })
    public Object auth22(String number,String no,Integer money) throws UpyztException {
        return    RefundExample.runDemos(number,no,money);
 
 
//        DepositResp balanceAcctResp = null;
//        try {
//            balanceAcctResp = DepositExample.retrieveById(number);
////            balanceAcctResp = DepositExample.retrieveById("2008429872055963229");
//            System.err.println(balanceAcctResp);
//        } catch (UpyztException e) {
//            System.out.println("电子账簿查询失败:{}"+e.getMessage());
//            e.printStackTrace();
//        }
//        System.out.println("电子账簿查询完成=========:{}"+balanceAcctResp);
 
 
 
//            BalanceAcctListResp balanceAcctListResp = null;
//            try {
//                BalanceAcctReq balanceAcctReq = new BalanceAcctReq();
//                balanceAcctReq.setMchId("1008427961477222943");
//                balanceAcctListResp = BalanceAcctExample.retrieveByUserId(balanceAcctReq);
//                System.err.println(balanceAcctListResp);
//            } catch (UpyztException e) {
//                System.err.println("电子账簿查询失败:{}"+e.getMessage());
//                e.printStackTrace();
//            }
//            System.err.println("电子账簿查询完成=========:{}"+balanceAcctListResp);
//        return balanceAcctListResp;
 
 
//        DepositReq depositReq = new DepositReq();
//        depositReq.setOutOrderNo(ToolUtil.getRandomString(32));
//        //-
//        depositReq.setAmount(1); // 支付金额
//        depositReq.setBalanceAcctId("2007907058462291527");
//        depositReq.setDepositType("1");
//        depositReq.setPaymentType(PaymentTypeEnum.CUP_APP.getCode());
//        //-
//        depositReq.setPaymentTradeNo("88890525-135");
//        depositReq.setPaymentSucceededAt(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(new Date()));
//        //-
//        depositReq.setOrderNo("88890525-135");
//        depositReq.setOrderAmount(1L);
//        depositReq.setProductName("充值金额");
//        depositReq.setProductCount(1);
//        depositReq.setNotifyUrl("http://zhentonggongsi.com:8010/api/placeOrder/notifyUrlOne");
//        DepositResp depositResp = null;
//        try {
//            depositResp = DepositExample.create(depositReq);
//        } catch (UpyztException e) {
//            System.err.println(e.getMessage());
//            e.printStackTrace();
//        }
//        System.err.println(depositResp);
//        System.err.println("支付充值成功:{}"+depositResp);
//        return depositResp;
 
    }
 
//    @ResponseBody
//    @RequestMapping(value = "/addTodayActivity", method = RequestMethod.POST)
//    @ApiOperation(value = "生成当天的司机活动", tags = {"生成当天的司机活动"}, notes = "")
//    public void addTodayActivity(){
//        try {
//            driverService.addTodayActivity();
//        } catch (Exception e) {
//            throw new RuntimeException(e);
//        }
//    }
 
 
    @RequestMapping(value = "/notify",method = RequestMethod.POST)
    public void notify(JSONObject jsonObject,HttpServletRequest request, HttpServletResponse resp) {
 
        // 获取参数
        System.err.println("回调参数:"+jsonObject);
//        Map<String, String[]> parameterMap = request.getParameterMap();
        if(Objects.isNull(jsonObject)){
            resp.setStatus(500);
            return;
        }
        String event_type = jsonObject.getString("event_type");
        if("trade_result".equals(event_type)){
            // 交易结果通知
            JSONObject event_data = jsonObject.getJSONObject("event_data");
            Integer trade_type = event_data.getInteger("trade_type");
            String out_order_no = event_data.getString("out_order_no");
            String status = event_data.getString("status");
            if("succeeded".equals(status)){
                if(20 == trade_type){
                    // 支付充值
                }
                if(25 == trade_type){
                    // 可提现支付充值
                }
                if(30 == trade_type){
                    // 提现
                }
                if(51 == trade_type){
                    // 分账
                }
            }
        }
        //返回给银联服务器http 200  状态码
        resp.setStatus(200);
    }
    /**
     * 测试接口是否走鉴权
     */
    @RequestMapping(value = "/test", method = RequestMethod.POST)
    public Object test() {
        return SUCCESS_TIP;
    }
 
}