Commit 8b145b1a by 吕明尚

美团验券,销券工具类

parent 99234a00
...@@ -66,7 +66,47 @@ ...@@ -66,7 +66,47 @@
<artifactId>hutool-all</artifactId> <artifactId>hutool-all</artifactId>
<version>5.8.16</version> <version>5.8.16</version>
</dependency> </dependency>
<!--美团SDK引入加相关依赖开始-->
<dependency>
<groupId>MtOpJavaSDK</groupId>
<artifactId>MtOpJavaSDK</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/lib/MtOpJavaSDK/MtOpJavaSDK-1.0-SNAPSHOT.jar</systemPath>
</dependency>
<dependency>
<groupId>MtOpJavaSDK-sources</groupId>
<artifactId>MtOpJavaSDK-sources</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/lib/MtOpJavaSDK/MtOpJavaSDK-1.0-SNAPSHOT-sources.jar</systemPath>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.9</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>3.0.1-b11</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
<!--美团SDK引入加相关依赖结束-->
</dependencies> </dependencies>
<build> <build>
......
##一、环境说明
美团开放平台Java版本SDK,支持jdk 1.8及以上版本。
##二、引入方式
下载jar包,添加到项目依赖中。SDK运行时需要依赖几个第三方库,如果您使用maven的话,直接添加以下依赖到pom.xml即可:
```xml
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.9</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>6.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>3.0.1-b11</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.25</version>
</dependency>
```
> 若您的项目中已包含上面的依赖,则忽略。
## 三、调用示例
以接口[门店本地验券历史](https://developer.meituan.com/docs/api/tuangou-coupon-queryLocalListByDate) 为例, DK提供了类***CouponQueryLocalListByDateRequest***来封装请求,您调用此接口的代码可以参考:
```java
Long developerId = 1111L;
String signKey = "xxxx";
String appAuthToken = "xxxxxxxxxxxxx";
//构造meituanClient,推荐使用单例方式,一个develoepr只使用一个实例
MeituanClient meituanClient = DefaultMeituanClient.builder(developerId, signKey).build();
//准备请求参数
CouponQueryLocalListByDateRequest request = new CouponQueryLocalListByDateRequest();
request.setDate("2020-12-15");
request.setOffset(0);
request.setLimit(10);
try {
//发起接口调用
MeituanResponse<CouponQueryLocalListByDateResponse> response = meituanClient.invokeApi(request, appAuthToken);
//判断是调用是否成功
if (response.isSuccess()) {
//调用成功,通过getData获取接口响应数据
CouponQueryLocalListByDateResponse localListByDateResponse = response.getData();
List<EOrders> eOrders = localListByDateResponse.getEOrders();
for(EOrders eOrder: eOrders) {
System.out.println(eOrder);
}
} else {
//调用失败,通过getCode和getMsg获取错误码和错误描述
System.out.println(response.getCode());
System.out.println(response.getMsg());
}
} catch (MtSdkException e) {
e.printStackTrace();
}
```
\ No newline at end of file
package share.utils;
import com.meituan.sdk.DefaultMeituanClient;
import com.meituan.sdk.MeituanClient;
import com.meituan.sdk.MeituanResponse;
import com.meituan.sdk.internal.exceptions.MtSdkException;
import com.meituan.sdk.model.tuangouNg.coupon.couponCancel.CouponCancelRequest;
import com.meituan.sdk.model.tuangouNg.coupon.couponCancel.CouponCancelResponse;
import com.meituan.sdk.model.tuangouNg.coupon.msSuperConsume.MsSuperConsumeRequest;
import com.meituan.sdk.model.tuangouNg.coupon.msSuperConsume.MsSuperConsumeResponse;
import org.springframework.beans.factory.annotation.Value;
public class MTUtil {
@Value("${meituan.developerId}")
private Long developerId;
@Value("${meituan.signKey}")
private String signKey;
@Value("${meituan.appAuthToken}")
private String appAuthToken;
//执行验券
public String VerificationVouchers(String code, int num){
//developerId 服务商身份标识 signKey 服务商签名密钥
MeituanClient meituanClient = DefaultMeituanClient.builder(developerId, signKey).build();
MsSuperConsumeRequest msSuperConsumeRequest = new MsSuperConsumeRequest();
// msSuperConsumeRequest.setCode("002300340045");
// msSuperConsumeRequest.setNum(1);
msSuperConsumeRequest.setCode(code);
msSuperConsumeRequest.setNum(num);
MeituanResponse<MsSuperConsumeResponse> response = null;
try {
response = meituanClient.invokeApi(msSuperConsumeRequest, appAuthToken);
} catch (MtSdkException e) {
throw new RuntimeException(e);
}
if (response.isSuccess()) {
MsSuperConsumeResponse resp = response.getData();
return resp.toString();
} else {
System.out.println("调用失败");
}
return null;
}
//
public String revoke (String ERPId ,String ERPName ,String couponCode){
MeituanClient meituanClient = DefaultMeituanClient.builder(developerId, signKey).build();
CouponCancelRequest couponCancelRequest = new CouponCancelRequest();
couponCancelRequest.setEId(ERPId);
couponCancelRequest.setEName(ERPName);
couponCancelRequest.setType(1);
couponCancelRequest.setCouponCode(couponCode);
MeituanResponse<CouponCancelResponse> response = null;
try {
response = meituanClient.invokeApi(couponCancelRequest, appAuthToken);
} catch (MtSdkException e) {
throw new RuntimeException(e);
}
if (response.isSuccess()) {
CouponCancelResponse resp = response.getData();
return resp.toString();
} else {
System.out.println("调用失败");
}
return null;
}
}
\ No newline at end of file
...@@ -28,7 +28,7 @@ import share.common.core.page.TableDataInfo; ...@@ -28,7 +28,7 @@ import share.common.core.page.TableDataInfo;
* @date 2023-09-27 * @date 2023-09-27
*/ */
@RestController @RestController
@RequestMapping("/system/coupon") @RequestMapping("/front/coupon")
public class SCouponController extends BaseController public class SCouponController extends BaseController
{ {
@Autowired @Autowired
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment