feat:免密支付
This commit is contained in:
1 parent
bbeef4536a
commit
0a2ec15518
9 files changed
+329
-184
No files matched your search
+27
@@ -0,0 +1,27 @@
|
||||
package com.bsd.pjcloud.app.api.constant;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* app用户类型
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public enum AppUserTypeEnum {
|
||||
|
||||
MINI_WECHAT("10", "微信小程序用户"),
|
||||
MINI_ALIPAY("20", "支付宝小程序用户"),
|
||||
;
|
||||
private final String type;
|
||||
private final String description;
|
||||
|
||||
public static AppUserTypeEnum valueOfByType(String type) {
|
||||
if (ObjectUtil.isEmpty(type)) return null;
|
||||
return Arrays.stream(values()).filter(v -> ObjectUtil.equals(type, v.getType())).findFirst().get();
|
||||
}
|
||||
|
||||
}
|
||||
+111
-99
@@ -40,122 +40,134 @@ import java.time.LocalDateTime;
|
||||
@Schema(description = "app用户表")
|
||||
public class AppUser extends Model<AppUser> {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* userId
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@Schema(description = "userId")
|
||||
private Long userId;
|
||||
/**
|
||||
* userId
|
||||
*/
|
||||
@TableId(type = IdType.ASSIGN_ID)
|
||||
@Schema(description = "userId")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@Schema(description = "用户名")
|
||||
private String username;
|
||||
/**
|
||||
* 用户类型
|
||||
*/
|
||||
@Schema(description = "用户类型")
|
||||
private String userType;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@Schema(description = "密码")
|
||||
private String password;
|
||||
/**
|
||||
* 用户名
|
||||
*/
|
||||
@Schema(description = "用户名")
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 随机盐
|
||||
*/
|
||||
@JsonIgnore
|
||||
@Schema(description = "随机盐")
|
||||
private String salt;
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
@Schema(description = "密码")
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
@Schema(description = "手机号")
|
||||
private String phone;
|
||||
/**
|
||||
* 随机盐
|
||||
*/
|
||||
@JsonIgnore
|
||||
@Schema(description = "随机盐")
|
||||
private String salt;
|
||||
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
@Schema(description = "头像")
|
||||
private String avatar;
|
||||
/**
|
||||
* 手机号
|
||||
*/
|
||||
@Schema(description = "手机号")
|
||||
private String phone;
|
||||
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
@Schema(description = "拓展字段:昵称")
|
||||
private String nickname;
|
||||
/**
|
||||
* 头像
|
||||
*/
|
||||
@Schema(description = "头像")
|
||||
private String avatar;
|
||||
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
@Schema(description = "拓展字段:姓名")
|
||||
private String name;
|
||||
/**
|
||||
* 昵称
|
||||
*/
|
||||
@Schema(description = "拓展字段:昵称")
|
||||
private String nickname;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
@Schema(description = "拓展字段:邮箱")
|
||||
private String email;
|
||||
/**
|
||||
* 姓名
|
||||
*/
|
||||
@Schema(description = "拓展字段:姓名")
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@Schema(description = "创建人")
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private String createBy;
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
@Schema(description = "拓展字段:邮箱")
|
||||
private String email;
|
||||
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
@Schema(description = "修改人")
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
private String updateBy;
|
||||
/**
|
||||
* 第三方登录扩展字段
|
||||
*/
|
||||
@Schema(description = "第三方登录扩展字段")
|
||||
private String loginExtJson;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间")
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
/**
|
||||
* 创建人
|
||||
*/
|
||||
@Schema(description = "创建人")
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private String createBy;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@Schema(description = "修改时间")
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
/**
|
||||
* 修改人
|
||||
*/
|
||||
@Schema(description = "修改人")
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
private String updateBy;
|
||||
|
||||
/**
|
||||
* 删除标记
|
||||
*/
|
||||
@Schema(description = "删除标记,1:已删除,0:正常")
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@TableLogic
|
||||
private String delFlag;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@Schema(description = "创建时间")
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 所属租户
|
||||
*/
|
||||
@Schema(description = "所属租户", hidden = true)
|
||||
private Long tenantId;
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
@Schema(description = "修改时间")
|
||||
@TableField(fill = FieldFill.UPDATE)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 最后一次密码修改时间
|
||||
*/
|
||||
@Schema(description = "最后一次密码修改时间")
|
||||
private LocalDateTime lastModifiedTime;
|
||||
/**
|
||||
* 删除标记
|
||||
*/
|
||||
@Schema(description = "删除标记,1:已删除,0:正常")
|
||||
@TableField(fill = FieldFill.INSERT)
|
||||
@TableLogic
|
||||
private String delFlag;
|
||||
|
||||
/**
|
||||
* 锁定标记
|
||||
*/
|
||||
@Schema(description = "锁定标记")
|
||||
private String lockFlag;
|
||||
/**
|
||||
* 所属租户
|
||||
*/
|
||||
@Schema(description = "所属租户", hidden = true)
|
||||
private Long tenantId;
|
||||
|
||||
/**
|
||||
* 微信小程序登录openId
|
||||
*/
|
||||
@Schema(description = "微信小程序登录openId")
|
||||
private String wxOpenid;
|
||||
/**
|
||||
* 最后一次密码修改时间
|
||||
*/
|
||||
@Schema(description = "最后一次密码修改时间")
|
||||
private LocalDateTime lastModifiedTime;
|
||||
|
||||
/**
|
||||
* 锁定标记
|
||||
*/
|
||||
@Schema(description = "锁定标记")
|
||||
private String lockFlag;
|
||||
|
||||
/**
|
||||
* openId
|
||||
*/
|
||||
@Schema(description = "openId")
|
||||
private String openid;
|
||||
|
||||
}
|
||||
+17
-22
@@ -27,32 +27,27 @@ import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
|
||||
/**
|
||||
* @author pjcloud
|
||||
* @date 2018/6/22
|
||||
*/
|
||||
|
||||
@FeignClient(contextId = "remoteAppUserService", value = ServiceNameConstants.APP_SERVER)
|
||||
public interface RemoteAppUserService {
|
||||
|
||||
/**
|
||||
* 通过用户名查询用户、角色信息
|
||||
* @param username 用户名
|
||||
* @param from 调用标志
|
||||
* @return R
|
||||
*/
|
||||
@NoToken
|
||||
@GetMapping("/appuser/info/{username}")
|
||||
R<AppUserInfo> info(@PathVariable("username") String username);
|
||||
/**
|
||||
* 通过用户名查询用户、角色信息
|
||||
*/
|
||||
@NoToken
|
||||
@GetMapping("/appuser/info/{username}")
|
||||
R<AppUserInfo> info(@PathVariable("username") String username);
|
||||
|
||||
/**
|
||||
* 通过社交账号或手机号查询用户、角色信息
|
||||
* @param inStr appid@code
|
||||
* @param from 调用标志
|
||||
* @return
|
||||
*/
|
||||
@NoToken
|
||||
@GetMapping("/appsocial/info/{inStr}")
|
||||
R<AppUserInfo> social(@PathVariable("inStr") String inStr);
|
||||
@NoToken
|
||||
@GetMapping("/appuser/infoByUserId/{userId}")
|
||||
R<AppUserInfo> infoByUserId(@PathVariable("userId") Long userId);
|
||||
|
||||
/**
|
||||
* 通过社交账号或手机号查询用户、角色信息
|
||||
*/
|
||||
@NoToken
|
||||
@GetMapping("/appsocial/info/{inStr}")
|
||||
R<AppUserInfo> social(@PathVariable("inStr") String inStr);
|
||||
|
||||
|
||||
}
|
||||
+15
@@ -81,6 +81,8 @@ public class AppUserController {
|
||||
|
||||
/* ************************************* end app end ************************************* */
|
||||
|
||||
/* ************************************* start 远程调用 start ************************************* */
|
||||
|
||||
@Inner
|
||||
@GetMapping("/info/{username}")
|
||||
public R info(@PathVariable String username) {
|
||||
@@ -95,6 +97,19 @@ public class AppUserController {
|
||||
return R.ok(appUserService.findUserInfo(user));
|
||||
}
|
||||
|
||||
@Inner
|
||||
@GetMapping("/infoByUserId/{userId}")
|
||||
public R<AppUserInfo> infoByUserId(@PathVariable Long userId) {
|
||||
AppUser user = appUserService.getOne(Wrappers.<AppUser>query()
|
||||
.lambda()
|
||||
.eq(AppUser::getUserId, userId)
|
||||
);
|
||||
if (user == null) return R.failed();
|
||||
return R.ok(appUserService.findUserInfo(user));
|
||||
}
|
||||
|
||||
/* ************************************* end 远程调用 end ************************************* */
|
||||
|
||||
/**
|
||||
* 分页查询
|
||||
*/
|
||||
|
||||
+9
-3
@@ -1,12 +1,14 @@
|
||||
package com.bsd.pjcloud.app.handler;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alipay.api.AlipayClient;
|
||||
import com.alipay.api.AlipayConfig;
|
||||
import com.alipay.api.DefaultAlipayClient;
|
||||
import com.alipay.api.request.AlipaySystemOauthTokenRequest;
|
||||
import com.alipay.api.response.AlipaySystemOauthTokenResponse;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
||||
import com.bsd.pjcloud.app.api.constant.AppUserTypeEnum;
|
||||
import com.bsd.pjcloud.app.api.dto.AppUserInfo;
|
||||
import com.bsd.pjcloud.app.api.entity.AppUser;
|
||||
import com.bsd.pjcloud.app.config.MiniAlipayConf;
|
||||
@@ -106,18 +108,22 @@ public class MiniAlipayLoginHandler extends AbstractLoginHandler {
|
||||
*/
|
||||
@Override
|
||||
public AppUserInfo info(String openId) {
|
||||
AppUser user = appUserService.getOne(Wrappers.<AppUser>query().lambda().eq(AppUser::getWxOpenid, openId));
|
||||
AppUser user = appUserService.getOne(Wrappers.<AppUser>query().lambda().eq(AppUser::getOpenid, openId));
|
||||
if (ObjectUtil.isEmpty(user)) {
|
||||
log.info("支付宝小程序openId:{},创建新的用户", openId);
|
||||
String name = "支付宝游客-" + openId;
|
||||
AppUser appUser = new AppUser();
|
||||
appUser.setWxOpenid(openId);
|
||||
appUser.setOpenid(openId);
|
||||
appUser.setUserType(AppUserTypeEnum.MINI_ALIPAY.getType());
|
||||
appUser.setUsername(name);
|
||||
appUser.setName(name);
|
||||
appUser.setCreateBy(openId);
|
||||
appUser.setUpdateBy(openId);
|
||||
appUserService.saveOrUpdate(appUser);
|
||||
return appUserService.findUserInfo(user);
|
||||
}
|
||||
if (ObjectUtil.isEmpty(user.getLoginExtJson())) {
|
||||
|
||||
}
|
||||
return appUserService.findUserInfo(user);
|
||||
}
|
||||
@@ -127,7 +133,7 @@ public class MiniAlipayLoginHandler extends AbstractLoginHandler {
|
||||
*/
|
||||
@Override
|
||||
public Boolean bind(AppUser user, String identify) {
|
||||
user.setWxOpenid(identify);
|
||||
user.setOpenid(identify);
|
||||
appUserService.updateById(user);
|
||||
return true;
|
||||
}
|
||||
|
||||
+3
-3
@@ -82,13 +82,13 @@ public class MiniWechatLoginHandler extends AbstractLoginHandler {
|
||||
*/
|
||||
@Override
|
||||
public AppUserInfo info(String openId) {
|
||||
AppUser user = appUserService.getOne(Wrappers.<AppUser>query().lambda().eq(AppUser::getWxOpenid, openId));
|
||||
AppUser user = appUserService.getOne(Wrappers.<AppUser>query().lambda().eq(AppUser::getOpenid, openId));
|
||||
|
||||
// 未注册用户自动注册
|
||||
if (Objects.isNull(user)) {
|
||||
log.info("微信小程序未绑定:{},创建新的用户", openId);
|
||||
AppUser appUser = new AppUser();
|
||||
appUser.setWxOpenid(openId);
|
||||
appUser.setOpenid(openId);
|
||||
appUser.setUsername(openId);
|
||||
appUser.setCreateBy(openId);
|
||||
appUser.setUpdateBy(openId);
|
||||
@@ -111,7 +111,7 @@ public class MiniWechatLoginHandler extends AbstractLoginHandler {
|
||||
*/
|
||||
@Override
|
||||
public Boolean bind(AppUser user, String identify) {
|
||||
user.setWxOpenid(identify);
|
||||
user.setOpenid(identify);
|
||||
appUserService.updateById(user);
|
||||
return true;
|
||||
}
|
||||
|
||||
+16
-6
@@ -1,8 +1,7 @@
|
||||
package com.bsd.pjcloud.hard.service;
|
||||
|
||||
|
||||
import com.alipay.api.response.AlipayFundAuthOrderAppFreezeResponse;
|
||||
import com.alipay.api.response.ZhimaCreditPayafteruseCreditagreementSignResponse;
|
||||
import com.alipay.api.response.*;
|
||||
|
||||
public interface MiniAlipayService {
|
||||
|
||||
@@ -12,12 +11,23 @@ public interface MiniAlipayService {
|
||||
String getDoorMiniQrCode(String hardDoorId, String cabinetNo);
|
||||
|
||||
/**
|
||||
* 支付宝冻结金额
|
||||
* 创建支付宝免密订单
|
||||
*/
|
||||
AlipayFundAuthOrderAppFreezeResponse freezeAmount(Long authId);
|
||||
AlipayTradeCreateResponse miCreateOrder(String openId, Long authId);
|
||||
|
||||
/**
|
||||
* 支付宝签约
|
||||
* 查询支付宝免密订单
|
||||
*/
|
||||
ZhimaCreditPayafteruseCreditagreementSignResponse creditagreementSign(Long authId);
|
||||
ZhimaCreditPayafteruseCreditbizorderQueryResponse miQueryOrder(String alipayOrderNo, String authId);
|
||||
|
||||
/**
|
||||
* 支付宝免密扣款
|
||||
*/
|
||||
AlipayTradeOrderPayResponse miQueryPay(String authId, String alipayTradeNo, int price);
|
||||
|
||||
/**
|
||||
* 支付宝免密(取消/退款)
|
||||
*/
|
||||
AlipayTradeRefundResponse miCancelOrRefund(String authId, String refundId, int price);
|
||||
|
||||
}
|
||||
+11
-5
@@ -1,14 +1,16 @@
|
||||
package com.bsd.pjcloud.hard.service.impl;
|
||||
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.alipay.api.response.AlipayFundAuthOrderAppFreezeResponse;
|
||||
import com.alipay.api.response.ZhimaCreditPayafteruseCreditagreementSignResponse;
|
||||
import com.alipay.api.response.AlipayTradeCreateResponse;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.bsd.pjcloud.admin.api.feign.RemoteUserService;
|
||||
import com.bsd.pjcloud.admin.api.utils.DataUtil;
|
||||
import com.bsd.pjcloud.admin.api.vo.UserVO;
|
||||
import com.bsd.pjcloud.app.api.dto.AppUserInfo;
|
||||
import com.bsd.pjcloud.app.api.entity.AppUser;
|
||||
import com.bsd.pjcloud.app.api.feign.RemoteAppUserService;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.UserTypeEnum;
|
||||
import com.bsd.pjcloud.common.core.constant.enums.YesNoEnum;
|
||||
import com.bsd.pjcloud.common.core.util.CollectionUtils;
|
||||
@@ -30,7 +32,6 @@ import com.bsd.pjcloud.hard.api.vo.order.HardAppCreateThirdDoorOrderVo;
|
||||
import com.bsd.pjcloud.hard.mapper.HardAuthMapper;
|
||||
import com.bsd.pjcloud.hard.mapper.manager.HardManagerMapper;
|
||||
import com.bsd.pjcloud.hard.service.*;
|
||||
import com.bsd.pjcloud.hard.service.impl.ali.MiniAlipayServiceImpl;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
@@ -58,6 +59,7 @@ public class HardAuthServiceImpl extends ServiceImpl<HardAuthMapper, HardAuthEnt
|
||||
private final HardManagerMapper hardManagerMapper;
|
||||
|
||||
private final RemoteUserService remoteUserService;
|
||||
private final RemoteAppUserService remoteAppUserService;
|
||||
|
||||
@Override
|
||||
public Page<HardAuthVo> scopePageJoin(Page page, HardAuthDto dto, DataScope dataScope) {
|
||||
@@ -134,6 +136,10 @@ public class HardAuthServiceImpl extends ServiceImpl<HardAuthMapper, HardAuthEnt
|
||||
// 查询设备信息
|
||||
HardDoorManagerVo hardDoorDetail = hardDoorManagerService.getByHardId(authEntity.getHardId());
|
||||
if (ObjectUtil.isEmpty(hardDoorDetail)) throw new RuntimeException("设备信息不存在");
|
||||
// 查询第三方用户信息
|
||||
AppUserInfo appUserInfo = remoteAppUserService.infoByUserId(dto.getUserId()).getData();
|
||||
if (ObjectUtil.isEmpty(appUserInfo)) throw new RuntimeException("第三方用户信息不存在");
|
||||
AppUser appUser = appUserInfo.getAppUser();
|
||||
|
||||
if (ObjectUtil.equals(dto.getAuthStatus(), YesNoEnum.NO.getCode())) {
|
||||
throw new RuntimeException("请先授权");
|
||||
@@ -141,11 +147,11 @@ public class HardAuthServiceImpl extends ServiceImpl<HardAuthMapper, HardAuthEnt
|
||||
|
||||
HardAppCreateThirdDoorOrderVo res = new HardAppCreateThirdDoorOrderVo();
|
||||
|
||||
ZhimaCreditPayafteruseCreditagreementSignResponse alipayRes = miniAlipayService.creditagreementSign(authEntity.getId());
|
||||
AlipayTradeCreateResponse alipayRes = miniAlipayService.miCreateOrder(appUser.getOpenid(), authEntity.getId());
|
||||
if (ObjectUtil.isEmpty(alipayRes)) {
|
||||
throw new RuntimeException("创建支付宝免密订单失败");
|
||||
}
|
||||
res.setAlipayOrderStr(alipayRes.getBody());
|
||||
res.setAlipayOrderStr(alipayRes.getTradeNo());
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
+120
-46
@@ -1,24 +1,26 @@
|
||||
package com.bsd.pjcloud.hard.service.impl.ali;
|
||||
|
||||
import cn.hutool.core.date.DatePattern;
|
||||
import cn.hutool.core.date.LocalDateTimeUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.json.JSONArray;
|
||||
import cn.hutool.json.JSONObject;
|
||||
import com.alipay.api.AlipayClient;
|
||||
import com.alipay.api.AlipayConfig;
|
||||
import com.alipay.api.DefaultAlipayClient;
|
||||
import com.alipay.api.domain.AlipayFundAuthOrderAppFreezeModel;
|
||||
import com.alipay.api.domain.AlipayOpenAppQrcodeCreateModel;
|
||||
import com.alipay.api.domain.ZhimaCreditPayafteruseCreditagreementSignModel;
|
||||
import com.alipay.api.request.AlipayFundAuthOrderAppFreezeRequest;
|
||||
import com.alipay.api.request.AlipayOpenAppQrcodeCreateRequest;
|
||||
import com.alipay.api.request.ZhimaCreditPayafteruseCreditagreementSignRequest;
|
||||
import com.alipay.api.response.AlipayFundAuthOrderAppFreezeResponse;
|
||||
import com.alipay.api.response.AlipayOpenAppQrcodeCreateResponse;
|
||||
import com.alipay.api.response.ZhimaCreditPayafteruseCreditagreementSignResponse;
|
||||
import com.alipay.api.domain.*;
|
||||
import com.alipay.api.request.*;
|
||||
import com.alipay.api.response.*;
|
||||
import com.bsd.pjcloud.hard.config.MiniAlipayConf;
|
||||
import com.bsd.pjcloud.hard.service.MiniAlipayService;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 支付宝小程序支付
|
||||
*/
|
||||
@@ -78,65 +80,137 @@ public class MiniAlipayServiceImpl implements MiniAlipayService {
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付宝冻结金额
|
||||
* 创建支付宝免密订单
|
||||
*/
|
||||
@Override
|
||||
public AlipayFundAuthOrderAppFreezeResponse freezeAmount(Long authId) {
|
||||
AlipayFundAuthOrderAppFreezeRequest request = new AlipayFundAuthOrderAppFreezeRequest();
|
||||
AlipayFundAuthOrderAppFreezeModel model = new AlipayFundAuthOrderAppFreezeModel();
|
||||
// 商户授权资金订单号(订单id)
|
||||
model.setOutOrderNo(String.valueOf(authId));
|
||||
// 商户本次资金操作的请求流水号,用于标示请求流水的唯一性(流程id)
|
||||
model.setOutRequestNo(String.valueOf(authId));
|
||||
// 订单标题
|
||||
model.setOrderTitle("浦江智能柜押金");
|
||||
// 设置需要冻结的金额(元)
|
||||
model.setAmount(conf.getFreezeAmount());
|
||||
// 设置销售产品码,商家和支付宝签约的产品码(固定)
|
||||
model.setProductCode("PREAUTH_PAY");
|
||||
// 设置收款账户的支付宝用户号
|
||||
model.setPayeeUserId(conf.getMerchantId());
|
||||
// 设置收款账户的支付宝登录号(email或手机号)
|
||||
model.setPayeeLogonId(conf.getMerchantAccount());
|
||||
// 设置预授权订单相对超时时间
|
||||
model.setTimeoutExpress("2d");
|
||||
request.setBizModel(model);
|
||||
public AlipayTradeCreateResponse miCreateOrder(String openId, Long authId) {
|
||||
AlipayTradeCreateRequest request = new AlipayTradeCreateRequest();
|
||||
try {
|
||||
AlipayFundAuthOrderAppFreezeResponse response = getClient().sdkExecute(request);
|
||||
JSONObject bizContent = new JSONObject();
|
||||
// 设置商户订单号
|
||||
bizContent.putOnce("out_trade_no", String.valueOf(authId));
|
||||
// 设置订单标题
|
||||
bizContent.putOnce("subject", "浦江智能柜芝麻先享");
|
||||
// 设置订单附加信息
|
||||
bizContent.putOnce("body", "浦江智能柜芝麻先享");
|
||||
// 设置订单金额
|
||||
bizContent.putOnce("total_amount", 5);
|
||||
// 固定
|
||||
bizContent.putOnce("product_code", "JSAPI_PAY");
|
||||
// 用户登录id
|
||||
bizContent.putOnce("buyer_open_id", openId);
|
||||
bizContent.putOnce("op_buyer_open_id", openId);
|
||||
bizContent.putOnce("op_app_id", conf.getAppId());
|
||||
// 订单超时时间(1天)
|
||||
bizContent.putOnce("time_expire", LocalDateTimeUtil.format(LocalDateTime.now().plusDays(1), DatePattern.NORM_DATETIME_FORMATTER));
|
||||
JSONObject extraParam = new JSONObject();
|
||||
extraParam.putOnce("zmServiceId", conf.getZmServiceId());
|
||||
extraParam.putOnce("creditTradeScene", "CREDIT_PAY");
|
||||
bizContent.putOnce("extend_params", extraParam);
|
||||
request.setBizContent(bizContent.toString());
|
||||
// request.setNotifyUrl("https://www.notifyURL.com");
|
||||
AlipayTradeCreateResponse response = getClient().execute(request);
|
||||
if (!response.isSuccess()) {
|
||||
log.error("|支付宝冻结金额|失败,json|{}", response.getBody());
|
||||
log.error("|创建支付宝订单|失败,json|{}", response.getBody());
|
||||
return null;
|
||||
}
|
||||
log.info("|支付宝冻结金额|成功,json|{}", response.getBody());
|
||||
log.info("|创建支付宝订单|成功,json|{}", response.getBody());
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("|支付宝冻结金额|意外的错误", e);
|
||||
log.error("|创建支付宝订单|意外的错误", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付宝签约
|
||||
* 查询支付宝免密订单
|
||||
*/
|
||||
public ZhimaCreditPayafteruseCreditagreementSignResponse creditagreementSign(Long authId) {
|
||||
ZhimaCreditPayafteruseCreditagreementSignRequest request = new ZhimaCreditPayafteruseCreditagreementSignRequest();
|
||||
ZhimaCreditPayafteruseCreditagreementSignModel model = new ZhimaCreditPayafteruseCreditagreementSignModel();
|
||||
// 设置芝麻信用服务ID
|
||||
model.setZmServiceId(conf.getZmServiceId());
|
||||
model.setOutAgreementNo(String.valueOf(authId));
|
||||
request.setBizModel(model);
|
||||
@Override
|
||||
public ZhimaCreditPayafteruseCreditbizorderQueryResponse miQueryOrder(String alipayOrderNo, String authId) {
|
||||
ZhimaCreditPayafteruseCreditbizorderQueryRequest request = new ZhimaCreditPayafteruseCreditbizorderQueryRequest();
|
||||
ZhimaCreditPayafteruseCreditbizorderQueryModel model = new ZhimaCreditPayafteruseCreditbizorderQueryModel();
|
||||
if (ObjectUtil.isNotEmpty(alipayOrderNo)) {
|
||||
model.setCreditBizOrderId(alipayOrderNo);
|
||||
}
|
||||
if (ObjectUtil.isNotEmpty(authId)) {
|
||||
model.setOutOrderNo(authId);
|
||||
}
|
||||
try {
|
||||
ZhimaCreditPayafteruseCreditagreementSignResponse response = getClient().sdkExecute(request);
|
||||
ZhimaCreditPayafteruseCreditbizorderQueryResponse response = getClient().execute(request);
|
||||
if (!response.isSuccess()) {
|
||||
log.error("|支付宝签约|失败,json|{}", response.getBody());
|
||||
log.error("|查询支付宝免密订单|失败,json|{}", response.getBody());
|
||||
return null;
|
||||
}
|
||||
log.info("|支付宝签约|成功,json|{}", response.getBody());
|
||||
log.info("|查询支付宝免密订单|成功,json|{}", response.getBody());
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("|支付宝签约|意外的错误", e);
|
||||
log.error("|查询支付宝免密订单|意外的错误", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付宝免密扣款
|
||||
*/
|
||||
@Override
|
||||
public AlipayTradeOrderPayResponse miQueryPay(String authId, String alipayTradeNo, int price) {
|
||||
AlipayTradeOrderPayRequest request = new AlipayTradeOrderPayRequest();
|
||||
JSONObject bizContent = new JSONObject();
|
||||
// 商家外部协议号,自定义确保唯一
|
||||
bizContent.put("out_request_no", authId);
|
||||
// 支付宝交易号
|
||||
bizContent.put("trade_no", alipayTradeNo);
|
||||
// 信用服务订单本次扣款金额,目前只支持全额扣款(传入的是分四舍五入)
|
||||
bizContent.put("fulfillment_amount", new BigDecimal(price).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP));
|
||||
// 固定值
|
||||
bizContent.put("order_pay_mode", "CREDIT_FULFILLMENT_ZM");
|
||||
try {
|
||||
request.setBizContent(bizContent.toString());
|
||||
AlipayTradeOrderPayResponse response = getClient().execute(request);
|
||||
if (!response.isSuccess()) {
|
||||
log.error("|支付宝免密扣款|失败,json|{}", response.getBody());
|
||||
return null;
|
||||
}
|
||||
log.info("|支付宝免密扣款|成功,json|{}", response.getBody());
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("|支付宝免密扣款|异常", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 支付宝免密(取消/退款)
|
||||
*/
|
||||
@Override
|
||||
public AlipayTradeRefundResponse miCancelOrRefund(String authId, String refundId, int price) {
|
||||
AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
|
||||
JSONObject bizContent = new JSONObject();
|
||||
|
||||
// 订单总金额
|
||||
bizContent.putOnce("refund_amount", new BigDecimal(price).divide(BigDecimal.valueOf(100), 2, RoundingMode.HALF_UP));
|
||||
// 商家订单唯一号
|
||||
bizContent.putOnce("out_trade_no", authId);
|
||||
bizContent.putOnce("out_request_no", refundId);
|
||||
//扩展参数
|
||||
JSONObject extendParam = new JSONObject();
|
||||
extendParam.putOnce("is_fulfilled", "true");
|
||||
bizContent.putOnce("extend_params", extendParam);
|
||||
try {
|
||||
request.setBizContent(bizContent.toString());
|
||||
AlipayTradeRefundResponse response = getClient().execute(request);
|
||||
if (!response.isSuccess()) {
|
||||
log.error("|支付宝免密(取消/退款)|失败,json|{}", response.getBody());
|
||||
return null;
|
||||
}
|
||||
log.info("|支付宝免密(取消/退款)|成功,json|{}", response.getBody());
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
log.error("|支付宝免密(取消/退款)|异常", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user