15 changed files with 776 additions and 2 deletions
@ -0,0 +1,34 @@ |
|||
package com.bnyer.img.config; |
|||
|
|||
import lombok.Getter; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.boot.context.properties.ConfigurationProperties; |
|||
import org.springframework.cloud.context.config.annotation.RefreshScope; |
|||
import org.springframework.context.annotation.Configuration; |
|||
|
|||
/** |
|||
* 云媒配置类 |
|||
* @author chengkun |
|||
* @date 2022/4/21 17:43 |
|||
*/ |
|||
@Configuration |
|||
@ConfigurationProperties(prefix = "yunmei") |
|||
@Getter |
|||
@RefreshScope |
|||
public class YunmeiConfig { |
|||
|
|||
@Value("${yunmei.appId}") |
|||
public String appId; |
|||
|
|||
@Value("${yunmei.appSecret}") |
|||
public String appSecret; |
|||
|
|||
@Value("${yunmei.url}") |
|||
public String url; |
|||
|
|||
@Value("${yunmei.version}") |
|||
public String version; |
|||
|
|||
@Value("${yunmei.notifyUrl}") |
|||
public String notifyUrl; |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
package com.bnyer.img.constants; |
|||
|
|||
/** |
|||
* 云媒敞亮类 |
|||
*/ |
|||
public class YunmeiConstant { |
|||
|
|||
|
|||
/** |
|||
* 商品列表 |
|||
*/ |
|||
public static final String PRODUCT_LIST = "/api/goods/list"; |
|||
|
|||
/** |
|||
* 商品详情 |
|||
*/ |
|||
public static final String PRODUCT_DETAILS = "/api/goods/get"; |
|||
|
|||
/** |
|||
* 直充/卡密下单 |
|||
*/ |
|||
public static final String CREATE_ORDER = "/api/order/create"; |
|||
|
|||
/** |
|||
* 订单查询 |
|||
*/ |
|||
public static final String ORDER_DETAILS = "/api/order/get"; |
|||
|
|||
/** |
|||
* 余额查询 |
|||
*/ |
|||
public static final String AMOUNT = "/api/account/balance"; |
|||
} |
|||
@ -0,0 +1,74 @@ |
|||
package com.bnyer.img.controller; |
|||
|
|||
import com.bnyer.common.core.web.controller.BaseController; |
|||
import com.bnyer.common.core.web.domain.AjaxResult; |
|||
import com.bnyer.img.dto.CardBuyOrderDto; |
|||
import com.bnyer.img.dto.DirectBuyOrderDto; |
|||
import com.bnyer.img.dto.OrderDetailsDto; |
|||
import com.bnyer.img.dto.OrderNotifyDto; |
|||
import com.bnyer.img.service.YunmeiService; |
|||
import io.swagger.annotations.Api; |
|||
import io.swagger.annotations.ApiOperation; |
|||
import io.swagger.annotations.ApiParam; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.web.bind.annotation.*; |
|||
|
|||
@Api(value = "【图文平台】云媒影视接口",tags = "【图文平台】云媒影视接口") |
|||
@RestController |
|||
@RequestMapping("/img/yunmei") |
|||
@Slf4j |
|||
public class YunmeiController extends BaseController { |
|||
|
|||
@Autowired |
|||
private YunmeiService yunmeiService; |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="查询云媒影视产品列表") |
|||
@PostMapping("/list") |
|||
public AjaxResult getProductList(){ |
|||
return AjaxResult.success(yunmeiService.getProductList()); |
|||
} |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="查询云媒影视产品详情") |
|||
@PostMapping("/details/{skuId}") |
|||
public AjaxResult getProductDetails(@ApiParam("商品id") @PathVariable("skuId") Long skuId){ |
|||
return AjaxResult.success(yunmeiService.getProductDetails(skuId)); |
|||
} |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="直充下单") |
|||
@PostMapping("/directBuy") |
|||
public AjaxResult directBuy(@ApiParam("直充下单参数") @RequestBody DirectBuyOrderDto params){ |
|||
return AjaxResult.success(yunmeiService.directBuyOrder(params)); |
|||
} |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="卡密下单") |
|||
@PostMapping("/cardBuy") |
|||
public AjaxResult cardBuy(@ApiParam("卡密下单参数") @RequestBody CardBuyOrderDto params){ |
|||
return AjaxResult.success(yunmeiService.cardBuyOrder(params)); |
|||
} |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="查询订单详情") |
|||
@PostMapping("/order/details") |
|||
public AjaxResult getProductDetails(@ApiParam("订单id对象") @RequestBody OrderDetailsDto params){ |
|||
return AjaxResult.success(yunmeiService.getOrderDetails(params.getOrderNo())); |
|||
} |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="查询商户余额") |
|||
@PostMapping("/balance") |
|||
public AjaxResult getBalance(){ |
|||
return AjaxResult.success(yunmeiService.getBalance()); |
|||
} |
|||
|
|||
//@RequiresPermissions("system:config:list")
|
|||
@ApiOperation(value="云媒订单回调") |
|||
@PostMapping("/notifyOrder") |
|||
public AjaxResult notifyOrder(@ApiParam("云媒回调参数") @RequestBody OrderNotifyDto params){ |
|||
return AjaxResult.success(yunmeiService.orderNotify(params)); |
|||
} |
|||
} |
|||
@ -0,0 +1,128 @@ |
|||
package com.bnyer.img.domain; |
|||
|
|||
import com.baomidou.mybatisplus.annotation.IdType; |
|||
import com.baomidou.mybatisplus.annotation.TableField; |
|||
import com.baomidou.mybatisplus.annotation.TableId; |
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import com.fasterxml.jackson.annotation.JsonFormat; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import java.io.Serializable; |
|||
import java.math.BigDecimal; |
|||
import java.util.Date; |
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Getter; |
|||
import lombok.NoArgsConstructor; |
|||
import lombok.Setter; |
|||
import lombok.ToString; |
|||
|
|||
@ApiModel(value="com-bnyer-img-domain-ProductOrder") |
|||
@Getter |
|||
@Setter |
|||
@ToString |
|||
@AllArgsConstructor |
|||
@NoArgsConstructor |
|||
@TableName(value = "img_product_order") |
|||
public class ProductOrder implements Serializable { |
|||
/** |
|||
* 主键id |
|||
*/ |
|||
@TableId(value = "id", type = IdType.AUTO) |
|||
@ApiModelProperty(value="主键id") |
|||
private Long id; |
|||
|
|||
/** |
|||
* 订单流水号 |
|||
*/ |
|||
@TableField(value = "order_id") |
|||
@ApiModelProperty(value="订单流水号") |
|||
private String orderId; |
|||
|
|||
/** |
|||
* 平台用户唯一id |
|||
*/ |
|||
@TableField(value = "user_code") |
|||
@ApiModelProperty(value="平台用户唯一id") |
|||
private String userCode; |
|||
|
|||
/** |
|||
* 商品价格 |
|||
*/ |
|||
@TableField(value = "product_price") |
|||
@ApiModelProperty(value="商品价格") |
|||
private BigDecimal productPrice; |
|||
|
|||
/** |
|||
* 支付价格 |
|||
*/ |
|||
@TableField(value = "pay_price") |
|||
@ApiModelProperty(value="支付价格") |
|||
private BigDecimal payPrice; |
|||
|
|||
/** |
|||
* 充值账号 |
|||
*/ |
|||
@TableField(value = "account_num") |
|||
@ApiModelProperty(value="充值账号") |
|||
private String accountNum; |
|||
|
|||
/** |
|||
* 订单类型(0->直充;1->卡密) |
|||
*/ |
|||
@TableField(value = "order_type") |
|||
@ApiModelProperty(value="订单类型(0->直充;1->卡密)") |
|||
private String orderType; |
|||
|
|||
/** |
|||
* 订单状态(0->待支付;1->支付中;2->已完成;3->已失效;4->支付失败) |
|||
*/ |
|||
@TableField(value = "order_status") |
|||
@ApiModelProperty(value="订单状态(0->待支付;1->支付中;2->已完成;3->已失效;4->支付失败)") |
|||
private String orderStatus; |
|||
|
|||
/** |
|||
* 账号类型(0->手机号;1->QQ号) |
|||
*/ |
|||
@TableField(value = "account_type") |
|||
@ApiModelProperty(value="账号类型(0->手机号;1->QQ号)") |
|||
private String accountType; |
|||
|
|||
/** |
|||
* 来源平台(0->抖音;1->快手;2->微信) |
|||
*/ |
|||
@TableField(value = "platform") |
|||
@ApiModelProperty(value="来源平台(0->抖音;1->快手;2->微信)") |
|||
private String platform; |
|||
|
|||
/** |
|||
* 支付方式(0->支付宝;1->微信支付) |
|||
*/ |
|||
@TableField(value = "pay_type") |
|||
@ApiModelProperty(value="支付方式(0->支付宝;1->微信支付)") |
|||
private String payType; |
|||
|
|||
/** |
|||
* 是否展示(0->否;1->是) |
|||
*/ |
|||
@TableField(value = "is_show") |
|||
@ApiModelProperty(value="是否展示(0->否;1->是)") |
|||
private String isShow; |
|||
|
|||
/** |
|||
* 创建时间 |
|||
*/ |
|||
@TableField(value = "create_time") |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@ApiModelProperty(value="创建时间") |
|||
private Date createTime; |
|||
|
|||
/** |
|||
* 更新时间 |
|||
*/ |
|||
@TableField(value = "update_time") |
|||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") |
|||
@ApiModelProperty(value="更新时间") |
|||
private Date updateTime; |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
package com.bnyer.img.dto; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import javax.validation.constraints.NotNull; |
|||
import java.io.Serializable; |
|||
|
|||
|
|||
@Getter |
|||
@Setter |
|||
@ApiModel("卡密下单接收类") |
|||
public class CardBuyOrderDto implements Serializable { |
|||
|
|||
@NotNull(message = "商品id不能为空!") |
|||
@ApiModelProperty(value="商品id") |
|||
private Integer skuId; |
|||
|
|||
@NotNull(message = "购买数量不能为空!") |
|||
@ApiModelProperty(value="购买数量") |
|||
private Integer buyQuantity; |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
package com.bnyer.img.dto; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import javax.validation.constraints.NotNull; |
|||
import java.io.Serializable; |
|||
|
|||
|
|||
@Getter |
|||
@Setter |
|||
@ApiModel("直充下单接收类") |
|||
public class DirectBuyOrderDto implements Serializable { |
|||
|
|||
@NotNull(message = "商品id不能为空!") |
|||
@ApiModelProperty(value="商品id") |
|||
private Integer skuId; |
|||
|
|||
@NotNull(message = "直充账号类型不能为空!") |
|||
@ApiModelProperty(value="直充账号类型,10:手机号;20:QQ号,30:邮箱;40:用户ID") |
|||
private Integer chargeAccountType; |
|||
|
|||
@NotBlank(message = "直充账号不能为空!") |
|||
@ApiModelProperty(value="直充账号") |
|||
private String chargeAccountNumber; |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,20 @@ |
|||
package com.bnyer.img.dto; |
|||
|
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import java.io.Serializable; |
|||
|
|||
|
|||
@Getter |
|||
@Setter |
|||
@ApiModel("云媒订单详情接收类") |
|||
public class OrderDetailsDto implements Serializable { |
|||
|
|||
@NotBlank(message = "订单id不能为空!") |
|||
@ApiModelProperty(value="订单id") |
|||
private String orderNo; |
|||
} |
|||
@ -0,0 +1,44 @@ |
|||
package com.bnyer.img.dto; |
|||
|
|||
import com.alibaba.fastjson.annotation.JSONField; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Getter; |
|||
import lombok.Setter; |
|||
|
|||
import javax.validation.constraints.NotBlank; |
|||
import javax.validation.constraints.NotNull; |
|||
import java.io.Serializable; |
|||
|
|||
|
|||
@Getter |
|||
@Setter |
|||
@ApiModel("订单回调接收类") |
|||
public class OrderNotifyDto implements Serializable { |
|||
|
|||
@NotBlank(message = "商户id不能为空!") |
|||
@ApiModelProperty(value="商户id") |
|||
private String app_id; |
|||
|
|||
@NotNull(message = "时间戳不能为空!") |
|||
@ApiModelProperty(value="时间戳") |
|||
private long timestamp; |
|||
|
|||
@NotBlank(message = "签名值不能为空!") |
|||
@ApiModelProperty(value="签名值") |
|||
private String sign; |
|||
|
|||
@NotBlank(message = "商户侧订单号不能为空!") |
|||
@ApiModelProperty(value="商户侧订单号") |
|||
private String customer_order_no; |
|||
|
|||
@NotBlank(message = "订单状态不能为空!") |
|||
@ApiModelProperty(value="订单状态(SUCCESS-成功;FAIL-失败)") |
|||
private String trade_state; |
|||
|
|||
@NotBlank(message = "描述信息不能为空!") |
|||
@ApiModelProperty(value="描述信息") |
|||
private String description; |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,19 @@ |
|||
package com.bnyer.img.enums; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Getter; |
|||
|
|||
/** |
|||
* @author chengkun |
|||
* @date 2022/4/19 17:46 |
|||
*/ |
|||
@Getter |
|||
@AllArgsConstructor |
|||
public enum YunmeiCallbackEnum { |
|||
SUCCESS("SUCCESS","ok"), |
|||
FAIL("FAIL","fail"); |
|||
|
|||
private String value; |
|||
|
|||
private String msg; |
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
package com.bnyer.img.enums; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Getter; |
|||
|
|||
/** |
|||
* @author chengkun |
|||
* @date 2022/4/19 17:46 |
|||
*/ |
|||
@Getter |
|||
@AllArgsConstructor |
|||
public enum YunmeiEnum { |
|||
SUCCESS(0,"接口调用成功"); |
|||
|
|||
private Integer code; |
|||
|
|||
private String msg; |
|||
} |
|||
@ -0,0 +1,7 @@ |
|||
package com.bnyer.img.mapper; |
|||
|
|||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
|||
import com.bnyer.img.domain.ProductOrder; |
|||
|
|||
public interface ProductOrderMapper extends BaseMapper<ProductOrder> { |
|||
} |
|||
@ -0,0 +1,57 @@ |
|||
package com.bnyer.img.service; |
|||
|
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.bnyer.img.dto.CardBuyOrderDto; |
|||
import com.bnyer.img.dto.DirectBuyOrderDto; |
|||
import com.bnyer.img.dto.OrderNotifyDto; |
|||
|
|||
public interface YunmeiService { |
|||
|
|||
/** |
|||
* 获取产品列表 |
|||
* @return - |
|||
*/ |
|||
JSONArray getProductList(); |
|||
|
|||
/** |
|||
* 根据商品id获取商品详情 |
|||
* @param skuId 商品Id |
|||
* @return - |
|||
*/ |
|||
JSONObject getProductDetails(Long skuId); |
|||
|
|||
/** |
|||
* 直充下单 |
|||
* @param params 下单参数 |
|||
* @return - |
|||
*/ |
|||
JSONObject directBuyOrder(DirectBuyOrderDto params); |
|||
|
|||
/** |
|||
* 卡密下单 |
|||
* @param params |
|||
* @return |
|||
*/ |
|||
JSONObject cardBuyOrder(CardBuyOrderDto params); |
|||
|
|||
/** |
|||
* 查询订单详情 |
|||
* @param orderNo 订单id |
|||
* @return - |
|||
*/ |
|||
JSONObject getOrderDetails(String orderNo); |
|||
|
|||
/** |
|||
* 查询商户余额 |
|||
* @return - |
|||
*/ |
|||
JSONObject getBalance(); |
|||
|
|||
/** |
|||
* 订单通知回调 |
|||
* @param params 回调参数 |
|||
* @return - |
|||
*/ |
|||
String orderNotify(OrderNotifyDto params); |
|||
} |
|||
@ -0,0 +1,245 @@ |
|||
package com.bnyer.img.service.impl; |
|||
|
|||
import cn.hutool.core.util.IdUtil; |
|||
import com.alibaba.fastjson.JSON; |
|||
import com.alibaba.fastjson.JSONArray; |
|||
import com.alibaba.fastjson.JSONObject; |
|||
import com.bnyer.common.core.exception.ServiceException; |
|||
import com.bnyer.img.config.YunmeiConfig; |
|||
import com.bnyer.img.constants.YunmeiConstant; |
|||
import com.bnyer.img.dto.CardBuyOrderDto; |
|||
import com.bnyer.img.dto.DirectBuyOrderDto; |
|||
import com.bnyer.img.dto.OrderNotifyDto; |
|||
import com.bnyer.img.enums.YunmeiCallbackEnum; |
|||
import com.bnyer.img.enums.YunmeiEnum; |
|||
import com.bnyer.img.service.YunmeiService; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.codec.digest.DigestUtils; |
|||
import org.springframework.beans.factory.annotation.Autowired; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.web.client.RestTemplate; |
|||
|
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
@Service |
|||
@Slf4j |
|||
public class YunmeiServiceImpl implements YunmeiService { |
|||
|
|||
@Autowired |
|||
private RestTemplate restTemplate; |
|||
|
|||
@Autowired |
|||
private YunmeiConfig yunmeiConfig; |
|||
|
|||
@Override |
|||
public JSONArray getProductList() { |
|||
long timeMillis = System.currentTimeMillis(); |
|||
String signContent = "app_id="+yunmeiConfig.getAppId()+"×tamp="+timeMillis |
|||
+"&version="+yunmeiConfig.getVersion()+"&app_secret="+yunmeiConfig.getAppSecret(); |
|||
log.debug("签名明文为:{}",signContent); |
|||
String sign = DigestUtils.md5Hex(signContent).toUpperCase(); |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("app_id",yunmeiConfig.getAppId()); |
|||
map.put("timestamp", timeMillis); |
|||
map.put("version", yunmeiConfig.getVersion()); |
|||
map.put("biz_content", ""); |
|||
map.put("sign", sign); |
|||
JSONObject result = restTemplate.postForObject(yunmeiConfig.getUrl() + YunmeiConstant.PRODUCT_LIST,map, JSONObject.class); |
|||
if(result != null && !result.getString("retcode").equals(YunmeiEnum.SUCCESS.getCode().toString())){ |
|||
log.error("###获取云媒产品列表失败!错误码为:{},错误信息为:{}",result.getString("retcode"),result.getString("retmsg")); |
|||
throw new ServiceException(result.getString("retmsg"),Integer.parseInt(result.getString("retcode"))); |
|||
} |
|||
return result.getJSONArray("data"); |
|||
} |
|||
|
|||
@Override |
|||
public JSONObject getProductDetails(Long skuId) { |
|||
long timeMillis = System.currentTimeMillis(); |
|||
Map<String,Object> bizMap = new HashMap<>(); |
|||
bizMap.put("sku_id",skuId); |
|||
String bizContent = JSON.toJSONString(bizMap); |
|||
String signContent = "app_id="+yunmeiConfig.getAppId()+"&biz_content="+ bizContent +"×tamp="+timeMillis |
|||
+"&version="+yunmeiConfig.getVersion()+"&app_secret="+yunmeiConfig.getAppSecret(); |
|||
log.debug("签名明文为:{}",signContent); |
|||
String sign = DigestUtils.md5Hex(signContent).toUpperCase(); |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("app_id",yunmeiConfig.getAppId()); |
|||
map.put("timestamp", timeMillis); |
|||
map.put("version", yunmeiConfig.getVersion()); |
|||
map.put("biz_content", bizContent); |
|||
map.put("sign",sign); |
|||
JSONObject result = restTemplate.postForObject(yunmeiConfig.getUrl() + YunmeiConstant.PRODUCT_DETAILS, map, JSONObject.class); |
|||
if(result != null){ |
|||
if(!result.getString("retcode").equals(YunmeiEnum.SUCCESS.getCode().toString())){ |
|||
log.error("###获取云媒产品【{}】详情失败!错误码为:{},错误信息为:{}",skuId,result.getString("retcode"),result.getString("retmsg")); |
|||
throw new ServiceException(result.getString("retmsg"),Integer.parseInt(result.getString("retcode"))); |
|||
} |
|||
if(result.getJSONObject("data") != null){ |
|||
return result.getJSONObject("data"); |
|||
}else{ |
|||
return null; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public JSONObject directBuyOrder(DirectBuyOrderDto params) { |
|||
long timeMillis = System.currentTimeMillis(); |
|||
String orderId = IdUtil.getSnowflakeNextIdStr(); |
|||
Map<String,Object> bizMap = new HashMap<>(); |
|||
bizMap.put("customer_order_no", orderId); |
|||
bizMap.put("sku_id", params.getSkuId()); |
|||
bizMap.put("order_type", 10); |
|||
bizMap.put("charge_acount_type", params.getChargeAccountType()); |
|||
bizMap.put("charge_acount_number", params.getChargeAccountNumber()); |
|||
String bizContent = JSON.toJSONString(bizMap); |
|||
String signContent = "app_id="+yunmeiConfig.getAppId()+"&biz_content="+ bizContent +"¬ify_url="+yunmeiConfig.getNotifyUrl() |
|||
+"×tamp="+timeMillis+"&version="+yunmeiConfig.getVersion()+"&app_secret="+yunmeiConfig.getAppSecret(); |
|||
log.debug("签名明文为:{}",signContent); |
|||
String sign = DigestUtils.md5Hex(signContent).toUpperCase(); |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("app_id",yunmeiConfig.getAppId()); |
|||
map.put("timestamp", timeMillis); |
|||
map.put("version", yunmeiConfig.getVersion()); |
|||
map.put("notify_url", yunmeiConfig.getNotifyUrl()); |
|||
map.put("biz_content", bizContent); |
|||
map.put("sign",sign); |
|||
JSONObject result = restTemplate.postForObject(yunmeiConfig.getUrl() + YunmeiConstant.CREATE_ORDER, map, JSONObject.class); |
|||
if(result != null){ |
|||
if(!result.getString("retcode").equals(YunmeiEnum.SUCCESS.getCode().toString())){ |
|||
log.error("###账号【{}】订单id【{}】直充下单产品【{}】失败!错误码为:{},错误信息为:{}",params.getChargeAccountNumber(),orderId,params.getSkuId(),result.getString("retcode"),result.getString("retmsg")); |
|||
throw new ServiceException(result.getString("retmsg"),Integer.parseInt(result.getString("retcode"))); |
|||
} |
|||
if(result.getJSONObject("data") != null){ |
|||
return result.getJSONObject("data"); |
|||
}else{ |
|||
return null; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public JSONObject cardBuyOrder(CardBuyOrderDto params) { |
|||
String orderId = IdUtil.getSnowflakeNextIdStr(); |
|||
long timeMillis = System.currentTimeMillis(); |
|||
Map<String,Object> bizMap = new HashMap<>(); |
|||
bizMap.put("customer_order_no", orderId); |
|||
bizMap.put("sku_id", params.getSkuId()); |
|||
bizMap.put("order_type", 20); |
|||
bizMap.put("buy_quantity", params.getBuyQuantity()); |
|||
String bizContent = JSON.toJSONString(bizMap); |
|||
String signContent = "app_id="+yunmeiConfig.getAppId()+"&biz_content="+ bizContent +"¬ify_url="+yunmeiConfig.getNotifyUrl() |
|||
+"×tamp="+timeMillis+"&version="+yunmeiConfig.getVersion()+"&app_secret="+yunmeiConfig.getAppSecret(); |
|||
log.debug("签名明文为:{}",signContent); |
|||
String sign = DigestUtils.md5Hex(signContent).toUpperCase(); |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("app_id",yunmeiConfig.getAppId()); |
|||
map.put("timestamp", timeMillis); |
|||
map.put("version", yunmeiConfig.getVersion()); |
|||
map.put("notify_url", yunmeiConfig.getNotifyUrl()); |
|||
map.put("biz_content", bizContent); |
|||
map.put("sign",sign); |
|||
JSONObject result = restTemplate.postForObject(yunmeiConfig.getUrl() + YunmeiConstant.CREATE_ORDER, map, JSONObject.class); |
|||
if(result != null){ |
|||
if(!result.getString("retcode").equals(YunmeiEnum.SUCCESS.getCode().toString())){ |
|||
log.error("###订单id【{}】卡密下单产品【{}】失败!错误码为:{},错误信息为:{}",orderId,params.getSkuId(),result.getString("retcode"),result.getString("retmsg")); |
|||
throw new ServiceException(result.getString("retmsg"),Integer.parseInt(result.getString("retcode"))); |
|||
} |
|||
if(result.getJSONObject("data") != null){ |
|||
return result.getJSONObject("data"); |
|||
}else{ |
|||
return null; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public JSONObject getOrderDetails(String orderNo) { |
|||
long timeMillis = System.currentTimeMillis(); |
|||
Map<String,Object> bizMap = new HashMap<>(); |
|||
bizMap.put("customer_order_no",orderNo); |
|||
String bizContent = JSON.toJSONString(bizMap); |
|||
String signContent = "app_id="+yunmeiConfig.getAppId()+"&biz_content="+ bizContent +"×tamp="+timeMillis |
|||
+"&version="+yunmeiConfig.getVersion()+"&app_secret="+yunmeiConfig.getAppSecret(); |
|||
log.debug("签名明文为:{}",signContent); |
|||
String sign = DigestUtils.md5Hex(signContent).toUpperCase(); |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("app_id",yunmeiConfig.getAppId()); |
|||
map.put("timestamp", timeMillis); |
|||
map.put("version", yunmeiConfig.getVersion()); |
|||
map.put("biz_content", bizContent); |
|||
map.put("sign",sign); |
|||
JSONObject result = restTemplate.postForObject(yunmeiConfig.getUrl() + YunmeiConstant.ORDER_DETAILS, map, JSONObject.class); |
|||
if(result != null){ |
|||
if(!result.getString("retcode").equals(YunmeiEnum.SUCCESS.getCode().toString())){ |
|||
log.error("###订单id【{}】查询订单详情失败!错误码为:{},错误信息为:{}",orderNo,result.getString("retcode"),result.getString("retmsg")); |
|||
throw new ServiceException(result.getString("retmsg"),Integer.parseInt(result.getString("retcode"))); |
|||
} |
|||
if(result.getJSONObject("data") != null){ |
|||
return result.getJSONObject("data"); |
|||
}else{ |
|||
return null; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public JSONObject getBalance() { |
|||
long timeMillis = System.currentTimeMillis(); |
|||
String signContent = "app_id="+yunmeiConfig.getAppId()+"×tamp="+timeMillis |
|||
+"&version="+yunmeiConfig.getVersion()+"&app_secret="+yunmeiConfig.getAppSecret(); |
|||
log.debug("签名明文为:{}",signContent); |
|||
String sign = DigestUtils.md5Hex(signContent).toUpperCase(); |
|||
Map<String, Object> map = new HashMap<>(); |
|||
map.put("app_id",yunmeiConfig.getAppId()); |
|||
map.put("timestamp", timeMillis); |
|||
map.put("version", yunmeiConfig.getVersion()); |
|||
map.put("biz_content", ""); |
|||
map.put("sign", sign); |
|||
JSONObject result = restTemplate.postForObject(yunmeiConfig.getUrl() + YunmeiConstant.AMOUNT,map, JSONObject.class); |
|||
if(result != null){ |
|||
if(!result.getString("retcode").equals(YunmeiEnum.SUCCESS.getCode().toString())){ |
|||
log.error("###查询商户余额失败!错误码为:{},错误信息为:{}",result.getString("retcode"),result.getString("retmsg")); |
|||
throw new ServiceException(result.getString("retmsg"),Integer.parseInt(result.getString("retcode"))); |
|||
} |
|||
if(result.getJSONObject("data") != null){ |
|||
return result.getJSONObject("data"); |
|||
}else{ |
|||
return null; |
|||
} |
|||
} |
|||
return null; |
|||
} |
|||
|
|||
@Override |
|||
public String orderNotify(OrderNotifyDto params) { |
|||
//验证商户id
|
|||
if(!params.getApp_id().equals(yunmeiConfig.getAppId())){ |
|||
log.error("###云媒订单【{}】回调失败!商户id【{}】不匹配!",params.getCustomer_order_no(),params.getApp_id()); |
|||
return YunmeiCallbackEnum.FAIL.getValue(); |
|||
} |
|||
//验证签名
|
|||
String signContent = "app_id="+params.getApp_id()+"&customer_order_no="+params.getCustomer_order_no() |
|||
+"&description="+params.getDescription()+"×tamp="+params.getTimestamp() |
|||
+"&trade_state="+params.getTrade_state()+"&app_secret="+yunmeiConfig.getAppSecret(); |
|||
log.debug("签名明文为:{}",signContent); |
|||
String sign = DigestUtils.md5Hex(signContent).toUpperCase(); |
|||
if(!sign.equals(params.getSign())){ |
|||
log.error("###云媒订单【{}】回调失败!签名参数【{}】不匹配!",params.getCustomer_order_no(),JSON.toJSONString(params)); |
|||
return YunmeiCallbackEnum.FAIL.getValue(); |
|||
} |
|||
//验证订单状态
|
|||
if(!params.getTrade_state().equals(YunmeiCallbackEnum.SUCCESS.getValue())){ |
|||
log.error("###云媒回调订单【{}】失败!错误信息为【{}】",params.getCustomer_order_no(),params.getDescription()); |
|||
return YunmeiCallbackEnum.FAIL.getValue(); |
|||
} |
|||
//TODO 回调成功,修改订单状态
|
|||
log.info("###云媒订单【{}】回调成功!",params.getCustomer_order_no()); |
|||
return YunmeiCallbackEnum.SUCCESS.getValue(); |
|||
} |
|||
} |
|||
@ -0,0 +1,27 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
|||
<mapper namespace="com.bnyer.img.mapper.ProductOrderMapper"> |
|||
<resultMap id="BaseResultMap" type="com.bnyer.img.domain.ProductOrder"> |
|||
<!--@mbg.generated--> |
|||
<!--@Table img_product_order--> |
|||
<id column="id" jdbcType="BIGINT" property="id" /> |
|||
<result column="order_id" jdbcType="VARCHAR" property="orderId" /> |
|||
<result column="user_code" jdbcType="VARCHAR" property="userCode" /> |
|||
<result column="product_price" jdbcType="DECIMAL" property="productPrice" /> |
|||
<result column="pay_price" jdbcType="DECIMAL" property="payPrice" /> |
|||
<result column="account_num" jdbcType="VARCHAR" property="accountNum" /> |
|||
<result column="order_type" jdbcType="CHAR" property="orderType" /> |
|||
<result column="order_status" jdbcType="CHAR" property="orderStatus" /> |
|||
<result column="account_type" jdbcType="CHAR" property="accountType" /> |
|||
<result column="platform" jdbcType="CHAR" property="platform" /> |
|||
<result column="pay_type" jdbcType="CHAR" property="payType" /> |
|||
<result column="is_show" jdbcType="CHAR" property="isShow" /> |
|||
<result column="create_time" jdbcType="TIMESTAMP" property="createTime" /> |
|||
<result column="update_time" jdbcType="TIMESTAMP" property="updateTime" /> |
|||
</resultMap> |
|||
<sql id="Base_Column_List"> |
|||
<!--@mbg.generated--> |
|||
id, order_id, user_code, product_price, pay_price, account_num, order_type, order_status, |
|||
account_type, platform, pay_type, is_show, create_time, update_time |
|||
</sql> |
|||
</mapper> |
|||
Loading…
Reference in new issue