update
This commit is contained in:
@@ -6,7 +6,8 @@ import cn.pluss.platform.api.ResultGenerator;
|
||||
import cn.pluss.platform.entitiy.PushCidAlias;
|
||||
import cn.pluss.platform.entity.UserApp;
|
||||
import cn.pluss.platform.userApp.UserAppService;
|
||||
import cn.pluss.platform.util.MobV2PushUtil;
|
||||
import cn.pluss.platform.util.MobV2PushUtilAndroid;
|
||||
import cn.pluss.platform.util.MobV2PushUtilIOS;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.Setter;
|
||||
@@ -20,9 +21,9 @@ import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.*;
|
||||
|
||||
@@ -68,15 +69,28 @@ public class PushController {
|
||||
* @throws NoSuchAlgorithmException
|
||||
*/
|
||||
@PostMapping("/bindalias")
|
||||
public Result<Object> bindAlias(@RequestBody Map<String, Object> param) throws IOException, NoSuchAlgorithmException {
|
||||
public Result<Object> bindAlias(@RequestBody Map<String, Object> param, HttpServletRequest httpServletRequest) throws IOException, NoSuchAlgorithmException {
|
||||
|
||||
UserApp userApp = userAppService.queryUserAppByToken();
|
||||
|
||||
String uid = userApp.getUserId().toString();
|
||||
String cid = param.get("cid").toString();
|
||||
|
||||
MobV2PushUtil mobV2PushUtil = new MobV2PushUtil();
|
||||
String token = mobV2PushUtil.getToken();
|
||||
String deviceType = httpServletRequest.getHeader("type");
|
||||
|
||||
String token = "";
|
||||
String aliasUrl = "";
|
||||
|
||||
if (deviceType.equals("1")) {
|
||||
MobV2PushUtilAndroid mobV2PushUtil = new MobV2PushUtilAndroid();
|
||||
token = mobV2PushUtil.getToken();
|
||||
aliasUrl = "https://restapi.getui.com/v2/" + MobV2PushUtilAndroid.appId + "/user/alias";
|
||||
|
||||
} else if (deviceType.equals("2")) {
|
||||
MobV2PushUtilIOS mobV2PushUtilIOS = new MobV2PushUtilIOS();
|
||||
token = mobV2PushUtilIOS.getToken();
|
||||
aliasUrl = "https://restapi.getui.com/v2/" + MobV2PushUtilIOS.appId + "/user/alias";
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
|
||||
@@ -99,8 +113,7 @@ public class PushController {
|
||||
// 设置为UTF8编码
|
||||
restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
|
||||
|
||||
String tokenInfo = restTemplate.postForObject(
|
||||
"https://restapi.getui.com/v2/" + MobV2PushUtil.appId + "/user/alias", httpEntity,
|
||||
String tokenInfo = restTemplate.postForObject(aliasUrl, httpEntity,
|
||||
String.class);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
@@ -122,15 +135,28 @@ public class PushController {
|
||||
* @throws NoSuchAlgorithmException
|
||||
*/
|
||||
@PostMapping("/unbindingAlias")
|
||||
public Result<Object> unbindingAlias(@RequestBody Map<String, Object> param) throws IOException, NoSuchAlgorithmException {
|
||||
public Result<Object> unbindingAlias(@RequestBody Map<String, Object> param,HttpServletRequest httpServletRequest) throws IOException, NoSuchAlgorithmException {
|
||||
|
||||
UserApp userApp = userAppService.queryUserAppByToken();
|
||||
|
||||
String uid = userApp.getUserId().toString();
|
||||
String cid = param.get("cid").toString();
|
||||
|
||||
MobV2PushUtil mobV2PushUtil = new MobV2PushUtil();
|
||||
String token = mobV2PushUtil.getToken();
|
||||
String deviceType = httpServletRequest.getHeader("type");
|
||||
|
||||
String token = "";
|
||||
String aliasUrl = "";
|
||||
|
||||
if (deviceType.equals("1")) {
|
||||
MobV2PushUtilAndroid mobV2PushUtil = new MobV2PushUtilAndroid();
|
||||
token = mobV2PushUtil.getToken();
|
||||
aliasUrl = "https://restapi.getui.com/v2/" + MobV2PushUtilAndroid.appId + "/user/alias";
|
||||
|
||||
} else if (deviceType.equals("2")) {
|
||||
MobV2PushUtilIOS mobV2PushUtilIOS = new MobV2PushUtilIOS();
|
||||
token = mobV2PushUtilIOS.getToken();
|
||||
aliasUrl = "https://restapi.getui.com/v2/" + MobV2PushUtilIOS.appId + "/user/alias";
|
||||
}
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
|
||||
@@ -155,7 +181,7 @@ public class PushController {
|
||||
restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
|
||||
|
||||
// delete, entity直接设为null即可
|
||||
ResponseEntity<Map> resultEntity = restTemplate.exchange("https://restapi.getui.com/v2/" + MobV2PushUtil.appId + "/user/alias",
|
||||
ResponseEntity<Map> resultEntity = restTemplate.exchange(aliasUrl,
|
||||
HttpMethod.DELETE,
|
||||
httpEntity,
|
||||
Map.class);
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
package cn.pluss.platform.util;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.getui.push.v2.sdk.ApiHelper;
|
||||
import com.getui.push.v2.sdk.GtApiConfiguration;
|
||||
import com.getui.push.v2.sdk.api.PushApi;
|
||||
import com.getui.push.v2.sdk.common.ApiResult;
|
||||
import com.getui.push.v2.sdk.dto.req.Audience;
|
||||
import com.getui.push.v2.sdk.dto.req.AudienceDTO;
|
||||
import com.getui.push.v2.sdk.dto.req.Settings;
|
||||
import com.getui.push.v2.sdk.dto.req.message.PushBatchDTO;
|
||||
import com.getui.push.v2.sdk.dto.req.message.PushChannel;
|
||||
import com.getui.push.v2.sdk.dto.req.message.PushDTO;
|
||||
import com.getui.push.v2.sdk.dto.req.message.PushMessage;
|
||||
import com.getui.push.v2.sdk.dto.req.message.android.AndroidDTO;
|
||||
import com.getui.push.v2.sdk.dto.req.message.android.ThirdNotification;
|
||||
import com.getui.push.v2.sdk.dto.req.message.android.Ups;
|
||||
import com.getui.push.v2.sdk.dto.req.message.ios.Alert;
|
||||
import com.getui.push.v2.sdk.dto.req.message.ios.Aps;
|
||||
import com.getui.push.v2.sdk.dto.req.message.ios.IosDTO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.http.HttpEntity;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.converter.StringHttpMessageConverter;
|
||||
import org.springframework.web.client.RestTemplate;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
public class MobV2PushUtilAndroid {
|
||||
|
||||
public static final String appKey = "9f5Nw6Bvb982HvsN3sG1y5";
|
||||
public static final String appId = "jzSkfM0Wsk8uSDL2zwGu07";
|
||||
public static final String masterSecret = "rKk62FdLE486boNJHWBPb1";
|
||||
|
||||
public String getToken() throws IOException, NoSuchAlgorithmException {
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
Long timestamp = new Date().getTime();
|
||||
|
||||
String content = appKey + timestamp + masterSecret;
|
||||
|
||||
MessageDigest messageDigest = MessageDigest.getInstance("SHA-256");
|
||||
messageDigest.update(content.getBytes("UTF-8"));
|
||||
String sign = byte2Hex(messageDigest.digest());
|
||||
|
||||
map.put("sign", sign);
|
||||
map.put("timestamp", timestamp);
|
||||
map.put("appkey", appKey);
|
||||
|
||||
String json = new ObjectMapper().writeValueAsString(map);
|
||||
|
||||
HttpHeaders header = new HttpHeaders();
|
||||
header.setContentType(MediaType.APPLICATION_JSON);
|
||||
|
||||
HttpEntity<String> httpEntity = new HttpEntity<>(json, header);
|
||||
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
// 设置为UTF8编码
|
||||
restTemplate.getMessageConverters().set(1, new StringHttpMessageConverter(StandardCharsets.UTF_8));
|
||||
|
||||
String tokenInfo = restTemplate.postForObject(
|
||||
"https://restapi.getui.com/v2/" + appId + "/auth", httpEntity,
|
||||
String.class);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JsonNode jsonNode = mapper.readTree(tokenInfo);
|
||||
JsonNode code = jsonNode.get("code");
|
||||
if (code.asText().equals("0")) {
|
||||
return jsonNode.get("data").get("token").asText();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void sendSingleByAlias(List<String> alias, String title, String content, String ext) {
|
||||
|
||||
GtApiConfiguration apiConfiguration = new GtApiConfiguration();
|
||||
//填写应用配置,参数在“Uni Push”下的“应用配置”页面中获取
|
||||
apiConfiguration.setAppId(appId);
|
||||
apiConfiguration.setAppKey(appKey);
|
||||
apiConfiguration.setMasterSecret(masterSecret);
|
||||
apiConfiguration.setDomain("https://restapi.getui.com/v2/");
|
||||
// 实例化ApiHelper对象,用于创建接口对象
|
||||
ApiHelper apiHelper = ApiHelper.build(apiConfiguration);
|
||||
|
||||
// 创建对象,建议复用。目前有PushApi、StatisticApi、UserApi
|
||||
PushApi pushApi = apiHelper.creatApi(PushApi.class);
|
||||
|
||||
|
||||
PushBatchDTO pushBatchDTO = new PushBatchDTO();
|
||||
|
||||
for (String value : alias) {
|
||||
//根据cid进行单推
|
||||
PushDTO<Audience> pushDTO = new PushDTO<Audience>();
|
||||
// 设置推送参数,requestid需要每次变化唯一
|
||||
pushDTO.setRequestId(System.currentTimeMillis() + "");
|
||||
Settings settings = new Settings();
|
||||
pushDTO.setSettings(settings);
|
||||
//消息有效期,走厂商消息必须设置该值
|
||||
settings.setTtl(3600000);
|
||||
|
||||
//在线走个推通道时推送的消息体
|
||||
PushMessage pushMessage = new PushMessage();
|
||||
pushDTO.setPushMessage(pushMessage);
|
||||
//此格式的透传消息由 unipush 做了特殊处理,会自动展示通知栏。开发者也可自定义其它格式,在客户端自己处理。
|
||||
//pushMessage.setTransmission(" {title:\"标题\",content:\"内容\",payload:\"快银到账1万元\"}");
|
||||
|
||||
//pushMessage.setTransmission("{title:" + title + ", content:" + content + ext);
|
||||
|
||||
pushMessage.setTransmission("{title:\"" + title + "\",content:\"" + content + "\"," + ext);
|
||||
|
||||
// 设置接收人信息
|
||||
Audience audience = new Audience();
|
||||
//audience.addAlias("244");
|
||||
audience.addAlias(value);
|
||||
pushDTO.setAudience(audience);
|
||||
|
||||
|
||||
//设置离线推送时的消息体
|
||||
PushChannel pushChannel = new PushChannel();
|
||||
//安卓离线厂商通道推送的消息体
|
||||
AndroidDTO androidDTO = new AndroidDTO();
|
||||
Ups ups = new Ups();
|
||||
ThirdNotification thirdNotification = new ThirdNotification();
|
||||
ups.setNotification(thirdNotification);
|
||||
thirdNotification.setTitle(title);
|
||||
thirdNotification.setBody(content);
|
||||
thirdNotification.setClickType("intent");
|
||||
//注意:intent参数必须按下方文档(特殊参数说明)要求的固定格式传值,intent错误会导致客户端无法收到消息
|
||||
thirdNotification.setIntent("intent://io.dcloud.unipush/?#Intent;scheme=unipush;launchFlags=0x4000000;component=io.dcloud.HBuilder/io.dcloud.PandoraEntry;S.UP-OL-SU=true;S.title=测试标题;S.content=测试内容;S.payload=test;end");
|
||||
androidDTO.setUps(ups);
|
||||
pushChannel.setAndroid(androidDTO);
|
||||
|
||||
//ios离线apn通道推送的消息体
|
||||
/* Alert alert = new Alert();
|
||||
alert.setTitle(title);
|
||||
alert.setBody(content);
|
||||
Aps aps = new Aps();
|
||||
aps.setContentAvailable(0);
|
||||
aps.setSound("default");
|
||||
aps.setAlert(alert);
|
||||
IosDTO iosDTO = new IosDTO();
|
||||
iosDTO.setAps(aps);
|
||||
iosDTO.setType("notify");
|
||||
pushChannel.setIos(iosDTO);*/
|
||||
|
||||
pushDTO.setPushChannel(pushChannel);
|
||||
|
||||
pushBatchDTO.addPushDTO(pushDTO);
|
||||
}
|
||||
|
||||
|
||||
ApiResult<Map<String, Map<String, String>>> apiResult = pushApi.pushBatchByAlias(pushBatchDTO);
|
||||
|
||||
log.info("[uni推送]PushResult result is {}", apiResult.getData());
|
||||
|
||||
if (apiResult.isSuccess()) {
|
||||
// success
|
||||
System.out.println(apiResult.getData());
|
||||
} else {
|
||||
// failed
|
||||
System.out.println("code:" + apiResult.getCode() + ", msg: " + apiResult.getMsg());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 将byte转为16进制
|
||||
*
|
||||
* @param bytes
|
||||
* @return
|
||||
*/
|
||||
private static String byte2Hex(byte[] bytes) {
|
||||
StringBuffer stringBuffer = new StringBuffer();
|
||||
String temp = null;
|
||||
for (int i = 0; i < bytes.length; i++) {
|
||||
temp = Integer.toHexString(bytes[i] & 0xFF);
|
||||
if (temp.length() == 1) {
|
||||
// 1得到一位的进行补0操作
|
||||
stringBuffer.append("0");
|
||||
}
|
||||
stringBuffer.append(temp);
|
||||
}
|
||||
return stringBuffer.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -704,6 +704,10 @@ public class ApiPayServiceImpl implements ApiPayService {
|
||||
order.setMercUserId(userId);
|
||||
order.setAlias(merchant.getMerchantName());
|
||||
try {
|
||||
|
||||
//TODO测试金额上线会删除
|
||||
order.setConsumeFee(0.01);
|
||||
|
||||
JSONObject result = sxfPayService.tradePay(order, channel,merchant);
|
||||
|
||||
if(ResultCode.SUCCESS.code() != result.getInteger("code")){
|
||||
|
||||
@@ -4,6 +4,7 @@ import cn.pluss.platform.api.ResultCode;
|
||||
import cn.pluss.platform.channel.MerchantAuditService;
|
||||
import cn.pluss.platform.config.ParameterConfig;
|
||||
import cn.pluss.platform.constants.Constant;
|
||||
import cn.pluss.platform.device.MercOrderNewService;
|
||||
import cn.pluss.platform.dto.MemberScanPayDTO;
|
||||
import cn.pluss.platform.dto.MerChantOrderDTO;
|
||||
import cn.pluss.platform.entity.*;
|
||||
@@ -15,6 +16,8 @@ import cn.pluss.platform.suixingfu.SxfConstants;
|
||||
import cn.pluss.platform.sxf.SxfService;
|
||||
import cn.pluss.platform.sxf.pay.SxfPayService;
|
||||
import cn.pluss.platform.util.*;
|
||||
import cn.pluss.platform.ys.YsConfig;
|
||||
import cn.pluss.platform.ys.YsOldConstants;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@@ -58,6 +61,9 @@ public class SxfPayServiceImpl implements SxfPayService {
|
||||
@Resource
|
||||
private ExecutorService executorService;
|
||||
|
||||
@Resource
|
||||
private MercOrderNewService mercOrderNewService;
|
||||
|
||||
|
||||
@Override
|
||||
public JSONObject tradePay(MerchantOrder order, MerchantChannelStatus channel, MerchantBaseInfo merchant) {
|
||||
@@ -109,6 +115,7 @@ public class SxfPayServiceImpl implements SxfPayService {
|
||||
|
||||
/**
|
||||
* 统一返回参数校验
|
||||
*
|
||||
* @param resultMap
|
||||
* @return
|
||||
*/
|
||||
@@ -170,6 +177,7 @@ public class SxfPayServiceImpl implements SxfPayService {
|
||||
|
||||
/**
|
||||
* 随行付主扫逻辑
|
||||
*
|
||||
* @param merchantOrderDTO
|
||||
* @param order
|
||||
* @param
|
||||
@@ -259,6 +267,7 @@ public class SxfPayServiceImpl implements SxfPayService {
|
||||
|
||||
/**
|
||||
* 随行付退款
|
||||
*
|
||||
* @param order
|
||||
* @return
|
||||
*/
|
||||
@@ -519,6 +528,7 @@ public class SxfPayServiceImpl implements SxfPayService {
|
||||
|
||||
/**
|
||||
* 辅助接口获取用户WXOpenID
|
||||
*
|
||||
* @param memberScanPayDTO
|
||||
* @return
|
||||
*/
|
||||
@@ -561,7 +571,6 @@ public class SxfPayServiceImpl implements SxfPayService {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param userAuthCode
|
||||
* @param paymentApp
|
||||
* @return
|
||||
@@ -612,10 +621,10 @@ public class SxfPayServiceImpl implements SxfPayService {
|
||||
// }
|
||||
|
||||
/**
|
||||
* @description:随行付支付回调处理
|
||||
* @date: 2021/8/19 18:41
|
||||
* @param map:
|
||||
* @return java.util.Map<java.lang.String, java.lang.String>
|
||||
* @description:随行付支付回调处理
|
||||
* @date: 2021/8/19 18:41
|
||||
*/
|
||||
|
||||
@Override
|
||||
@@ -647,6 +656,26 @@ public class SxfPayServiceImpl implements SxfPayService {
|
||||
String channelOrderNo = map.get("transactionId");
|
||||
//支付成功
|
||||
if (SxfConfg.SXF_SUCCESS_CODE.equals(bizCode)) {
|
||||
|
||||
MercOrderNew newOrder = mercOrderNewService.getOrderByNo(ordNo);
|
||||
if (newOrder != null) {
|
||||
|
||||
log.info("====================>【随行付】新版设备订单回调,订单号:{}<====================", newOrder.getOrderNo());
|
||||
|
||||
String channelRecvNo = map.get("transactionId");
|
||||
if (Constant.PAY_TYPE_ALIPAY.equals(newOrder.getPayType())) {
|
||||
channelRecvNo = channelRecvNo.substring(2);
|
||||
}
|
||||
|
||||
Date payDate = DateUtils.parse(payTime, "yyyy-MM-dd HH:mm:ss");
|
||||
mercOrderNewService.devicePaySuccessNotifyV2(newOrder.getOrderNo(), uuid, channelRecvNo, payDate, newOrder);
|
||||
|
||||
result.put("code", "success");
|
||||
result.put("msg", "成功");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//退款通知
|
||||
Date payDate = new Date();
|
||||
try {
|
||||
@@ -693,9 +722,9 @@ public class SxfPayServiceImpl implements SxfPayService {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return java.lang.Boolean
|
||||
* @description:校验签名
|
||||
* @date: 2021/8/23 10:00
|
||||
* @return java.lang.Boolean
|
||||
*/
|
||||
private Boolean checkSign(Map<String, String> map) {
|
||||
String sign = map.get("sign");
|
||||
|
||||
Reference in New Issue
Block a user