Skip to content

Commit

Permalink
Merge pull request #3 from PMPanel/master
Browse files Browse the repository at this point in the history
version 1.0.4
  • Loading branch information
PMPanel authored May 7, 2022
2 parents 9ccb693 + 6184f06 commit c0befd2
Show file tree
Hide file tree
Showing 28 changed files with 692 additions and 480 deletions.
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,4 @@ The Proxy Manage Panel is an open source web application which can manage shadow

[TG Channel](https://t.me/PMPanel)

[TG Group](https://t.me/pmpanel_group)

---

### Donate

trc20-usdt: TGnSCyNujTUT9DYBvTDj4k3JsWdDgaHNU1
[TG Group](https://t.me/pmpanel_group)
13 changes: 10 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
</parent>
<groupId>project.daihao18</groupId>
<artifactId>pmpanel</artifactId>
<version>1.0.2</version>
<version>1.0.4</version>
<name>panel_backend</name>
<description>daihao18's pmpanel project</description>
<description>project pmpanel</description>

<properties>
<java.version>1.8</java.version>
<log4j2.version>2.15.0</log4j2.version>
<log4j2.version>2.17.0</log4j2.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -117,6 +117,13 @@
<version>2.7.0</version>
</dependency>

<!--stripe-->
<dependency>
<groupId>com.stripe</groupId>
<artifactId>stripe-java</artifactId>
<version>20.95.0</version>
</dependency>

<!--TG Bot-->
<dependency>
<groupId>com.github.pengrad</groupId>
Expand Down
1 change: 1 addition & 0 deletions sql/1.02-1.03.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `schedule`(`id`, `bean_name`, `method_name`, `method_params`, `cron_expression`, `remark`, `job_status`, `created_time`, `update_time`) VALUES (6, 'telegramJobTaskService', 'telegramJob', NULL, '*/2 * * * * ?', 'telegram任务', 1, '2020-11-11 11:11:11', NULL);
13 changes: 13 additions & 0 deletions sql/1.03-1.04.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
ALTER TABLE `order`
DROP COLUMN `is_mixed_pay`,
DROP COLUMN `mixed_money_amount`,
CHANGE COLUMN `mixed_pay_amount` `pay_amount` decimal(10, 2) NULL DEFAULT NULL COMMENT '支付金额' AFTER `price`;

ALTER TABLE `package`
DROP COLUMN `is_mixed_pay`,
DROP COLUMN `mixed_money_amount`,
CHANGE COLUMN `mixed_pay_amount` `pay_amount` decimal(10, 2) NULL DEFAULT NULL COMMENT '支付金额' AFTER `create_time`;

INSERT INTO `config`(`id`, `name`, `value`) VALUES (204, 'stripeConfig', '{\"sk_live\":\"\",\"webhook_secret\":\"\",\"currency\":\"\",\"return_url\":\"\"}');

ALTER TABLE `order` DROP FOREIGN KEY `order_planid`;
12 changes: 4 additions & 8 deletions sql/panel_all.sql
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,7 @@ CREATE TABLE `order` (
`plan_id` int DEFAULT '0' COMMENT '套餐id',
`month_count` int DEFAULT '0' COMMENT '订购月数',
`price` decimal(10,2) unsigned DEFAULT '0.00' COMMENT '应付价格',
`is_mixed_pay` int DEFAULT NULL COMMENT '是否混合支付(余额+支付网关)',
`mixed_money_amount` decimal(10,2) DEFAULT NULL COMMENT '混合支付余额金额',
`mixed_pay_amount` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '混合支付网关支付金额',
`pay_amount` decimal(10, 2) unsigned DEFAULT '0.00' COMMENT '支付金额',
`pay_type` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '支付网关支付类型',
`payer` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '支付者',
`is_new_payer` int DEFAULT '0' COMMENT '是否新用户',
Expand All @@ -141,8 +139,6 @@ CREATE TABLE `order` (
PRIMARY KEY (`id`),
UNIQUE KEY `order_id` (`order_id`) COMMENT '订单唯一',
KEY `order_userid` (`user_id`),
KEY `order_planid` (`plan_id`),
CONSTRAINT `order_planid` FOREIGN KEY (`plan_id`) REFERENCES `plan` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `order_userid` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='订单记录';

Expand All @@ -158,9 +154,7 @@ CREATE TABLE `package` (
`transfer_enable` bigint DEFAULT '0',
`expire` datetime DEFAULT CURRENT_TIMESTAMP,
`create_time` datetime DEFAULT CURRENT_TIMESTAMP,
`is_mixed_pay` int DEFAULT NULL COMMENT '是否混合支付(余额+支付网关)',
`mixed_money_amount` decimal(10,2) DEFAULT NULL COMMENT '混合支付余额金额',
`mixed_pay_amount` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '混合支付网关支付金额',
`pay_amount` decimal(10, 2) unsigned DEFAULT '0.00' COMMENT '支付金额',
`pay_type` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT '' COMMENT '支付网关支付类型',
`payer` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '支付者',
`pay_time` datetime DEFAULT NULL COMMENT '支付时间',
Expand Down Expand Up @@ -457,6 +451,7 @@ INSERT INTO `config`(`id`, `name`, `value`) VALUES (106, 'withdrawRate', '0.15')
INSERT INTO `config`(`id`, `name`, `value`) VALUES (201, 'alipay', 'none');
INSERT INTO `config`(`id`, `name`, `value`) VALUES (202, 'wxpay', 'none');
INSERT INTO `config`(`id`, `name`, `value`) VALUES (203, 'alipayConfig', '{\"appId\":\"\",\"pId\":\"\",\"isCertMode\":false,\"appPrivateKey\":\"\",\"alipayPublicKey\":\"\",\"appCertPath\":\"\",\"alipayCertPath\":\"\",\"alipayRootCertPath\":\"\",\"serverUrl\":\"https://openapi.alipay.com/gateway.do\",\"domain\":\"http://127.0.0.1\",\"web\":false,\"wap\":false,\"f2f\":false}');
INSERT INTO `config`(`id`, `name`, `value`) VALUES (204, 'stripeConfig', '{\"sk_live\":\"\",\"webhook_secret\":\"\",\"currency\":\"\",\"return_url\":\"\"}');
INSERT INTO `config`(`id`, `name`, `value`) VALUES (301, 'muSuffix', 'download.windowsupdate.com');
INSERT INTO `config`(`id`, `name`, `value`) VALUES (302, 'userTrafficLogLimitDays', '3');
INSERT INTO `config`(`id`, `name`, `value`) VALUES (401, 'clientConfig', '');
Expand All @@ -473,3 +468,4 @@ INSERT INTO `schedule`(`id`, `bean_name`, `method_name`, `method_params`, `cron_
INSERT INTO `schedule`(`id`, `bean_name`, `method_name`, `method_params`, `cron_expression`, `remark`, `job_status`, `created_time`, `update_time`) VALUES (3, 'checkJobTaskService', 'checkJob', NULL, '0 * * * * ?', '检查任务', 1, '2020-11-11 11:11:11', NULL);
INSERT INTO `schedule`(`id`, `bean_name`, `method_name`, `method_params`, `cron_expression`, `remark`, `job_status`, `created_time`, `update_time`) VALUES (4, 'checkOrderJobTaskService', 'checkOrderJob', NULL, '*/5 * * * * ?', '支付宝主动查单', 1, '2020-11-11 11:11:11', NULL);
INSERT INTO `schedule`(`id`, `bean_name`, `method_name`, `method_params`, `cron_expression`, `remark`, `job_status`, `created_time`, `update_time`) VALUES (5, 'notifyRenewJobTaskService', 'notifyRenewJob', NULL, '0 0 2 28 * ?', '月底发送续费通知邮件', 1, '2020-11-11 11:11:11', NULL);
INSERT INTO `schedule`(`id`, `bean_name`, `method_name`, `method_params`, `cron_expression`, `remark`, `job_status`, `created_time`, `update_time`) VALUES (6, 'telegramJobTaskService', 'telegramJob', NULL, '*/2 * * * * ?', 'telegram任务', 1, '2020-11-11 11:11:11', NULL);
7 changes: 7 additions & 0 deletions src/main/java/project/daihao18/panel/PanelApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,20 @@
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.client.RestTemplate;

@MapperScan(basePackages = {"project.daihao18.panel.mapper"})
@EnableTransactionManagement
@SpringBootApplication// (exclude = {JacksonAutoConfiguration.class})
public class PanelApplication {

@Bean
public RestTemplate restTemplate(){
return new RestTemplate();
}

public static void main(String[] args) {
SpringApplication.run(PanelApplication.class, args);
}
Expand Down
121 changes: 47 additions & 74 deletions src/main/java/project/daihao18/panel/common/payment/alipay/Alipay.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.springframework.transaction.annotation.Transactional;
import project.daihao18.panel.common.utils.FlowSizeConverterUtil;
import project.daihao18.panel.entity.CommonOrder;
import project.daihao18.panel.entity.Order;
import project.daihao18.panel.service.ConfigService;
import project.daihao18.panel.service.OrderService;
import project.daihao18.panel.service.PackageService;
Expand Down Expand Up @@ -125,7 +124,7 @@ protected void setAliPayApiConfig() throws AlipayApiException {
* @return
*/
@Transactional
public Map<String, Object> create(CommonOrder order, Boolean isMixedPay) throws AlipayApiException {
public Map<String, Object> create(CommonOrder order) throws AlipayApiException {
// 根据config配置的下单方式来下单
// 获取支付宝配置
Map<String, Object> alipayConfig = JSONUtil.toBean(configService.getValueByName("alipayConfig"), Map.class);
Expand All @@ -135,24 +134,27 @@ public Map<String, Object> create(CommonOrder order, Boolean isMixedPay) throws
// 设置通知的domain(本站域名)
order.setDomain(alipayConfig.get("domain").toString());
// 获取订单标题
String subject = "";
String subject = "Order#";
// 大写开头为混合支付
if ("plan".equals(order.getType())) {
subject = subject.concat(orderService.getOrderByOrderId(order.getId()).getPlanDetailsMap().get("name").toString());
subject = subject.concat(order.getId());
order.setId("p_".concat(order.getId()));
} else {
subject = subject.concat(FlowSizeConverterUtil.BytesToGb(packageService.getById(order.getId()).getTransferEnable()) + " GB");
order.setId("t_".concat(order.getId()));
}
// 通过请求的是pc 还是 h5来自动选择
Map<String, Object> result = new HashMap<>();
result.put("type", "alipay");
if ("pc".equals(order.getPlatform())) {
if (web) {
// 优先选择web
result = this.createByWEB(order, subject, isMixedPay);
result = this.createByWEB(order, subject);
result.put("type", "link");
return result;
} else if (f2f) {
// 没有web选择f2f
result = this.createByF2F(order, subject, isMixedPay);
result = this.createByF2F(order, subject);
result.put("type", "qr");
return result;
} else {
Expand All @@ -162,12 +164,12 @@ public Map<String, Object> create(CommonOrder order, Boolean isMixedPay) throws
} else if ("h5".equals(order.getPlatform())) {
if (wap) {
// 优先选择wap
result = this.createByWAP(order, subject, isMixedPay);
result = this.createByWAP(order, subject);
result.put("type", "link");
return result;
} else if (f2f) {
// 没有wap选择f2f
result = this.createByF2F(order, subject, isMixedPay);
result = this.createByF2F(order, subject);
result.put("type", "link");
return result;
} else {
Expand All @@ -185,15 +187,14 @@ public Map<String, Object> create(CommonOrder order, Boolean isMixedPay) throws
* @param order
* @return
*/
protected Map<String, Object> createByWEB(CommonOrder order, String subject, Boolean isMixedPay) throws AlipayApiException {
protected Map<String, Object> createByWEB(CommonOrder order, String subject) throws AlipayApiException {
AlipayTradePagePayRequest request = new AlipayTradePagePayRequest();
AlipayTradePagePayModel model = new AlipayTradePagePayModel();
model.setSubject(subject);
model.setProductCode("FAST_INSTANT_TRADE_PAY");
String isMixed = isMixedPay ? "1" : "0";
model.setOutTradeNo(order.getId() + "_" + isMixed);
model.setOutTradeNo(order.getId());
model.setTimeoutExpress("5m");
model.setTotalAmount(order.getMixedPayAmount().toString());
model.setTotalAmount(order.getPayAmount().toString());
model.setDisablePayChannels("credit_group");
request.setBizModel(model);
request.setNotifyUrl(order.getDomain() + ALIPAY_NOTIFY_URL);
Expand All @@ -211,15 +212,14 @@ protected Map<String, Object> createByWEB(CommonOrder order, String subject, Boo
* @param order
* @return
*/
protected Map<String, Object> createByWAP(CommonOrder order, String subject, Boolean isMixedPay) throws AlipayApiException {
protected Map<String, Object> createByWAP(CommonOrder order, String subject) throws AlipayApiException {
AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest();
AlipayTradeWapPayModel model = new AlipayTradeWapPayModel();
model.setSubject(subject);
model.setProductCode("QUICK_WAP_WAY");
String isMixed = isMixedPay ? "1" : "0";
model.setOutTradeNo(order.getId() + "_" + isMixed);
model.setOutTradeNo(order.getId());
model.setTimeoutExpress("5m");
model.setTotalAmount(order.getMixedPayAmount().toString());
model.setTotalAmount(order.getPayAmount().toString());
model.setDisablePayChannels("credit_group");
request.setBizModel(model);
request.setNotifyUrl(order.getDomain() + ALIPAY_NOTIFY_URL);
Expand All @@ -237,15 +237,13 @@ protected Map<String, Object> createByWAP(CommonOrder order, String subject, Boo
* @param order
* @return
*/
protected Map<String, Object> createByF2F(CommonOrder order, String subject, Boolean isMixedPay) throws AlipayApiException {
protected Map<String, Object> createByF2F(CommonOrder order, String subject) throws AlipayApiException {
AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest();
AlipayTradePrecreateModel model = new AlipayTradePrecreateModel();
model.setSubject(subject);
String isMixed = isMixedPay ? "1" : "0";
model.setOutTradeNo(order.getId() + "_" + isMixed);
// model.setOutTradeNo(order.getId() + "_" + isMixed + "_" + RandomUtil.randomNumbers(4));
model.setOutTradeNo(order.getId());
model.setTimeoutExpress("5m");
model.setTotalAmount(order.getMixedPayAmount().toString());
model.setTotalAmount(order.getPayAmount().toString());
model.setDisablePayChannels("credit_group");
request.setBizModel(model);
request.setNotifyUrl(order.getDomain() + ALIPAY_NOTIFY_URL);
Expand All @@ -272,31 +270,23 @@ protected Map<String, Object> createByF2F(CommonOrder order, String subject, Boo
public AlipayTradeQueryResponse query(CommonOrder order) throws AlipayApiException {
AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
AlipayTradeQueryModel model = new AlipayTradeQueryModel();
model.setOutTradeNo(order.getId() + "_0");

if ("plan".equals(order.getType())) {
order.setId("p_".concat(order.getId()));
} else {
order.setId("t_".concat(order.getId()));
}

model.setOutTradeNo(order.getId());
request.setBizModel(model);
// 设置alipayClient
// 查2次
AlipayTradeQueryResponse execute = null;
if (isCertMode) {
execute = alipayClient.certificateExecute(request);
} else {
execute = alipayClient.execute(request);
}
if (!"40004".equals(execute.getCode())) {
return execute;
} else {
model.setOutTradeNo(order.getId() + "_1");
request.setBizModel(model);
if (isCertMode) {
execute = alipayClient.certificateExecute(request);
} else {
execute = alipayClient.execute(request);
}
if (!"40004".equals(execute.getCode())) {
return execute;
}
}
return null;
return execute;
}

/**
Expand All @@ -307,38 +297,37 @@ public AlipayTradeQueryResponse query(CommonOrder order) throws AlipayApiExcepti
public AlipayTradeCloseResponse close(CommonOrder order) throws AlipayApiException {
AlipayTradeCloseRequest request = new AlipayTradeCloseRequest();
AlipayTradeCloseModel model = new AlipayTradeCloseModel();
model.setOutTradeNo(order.getId() + "_0");

if ("plan".equals(order.getType())) {
order.setId("p_".concat(order.getId()));
} else {
order.setId("t_".concat(order.getId()));
}

model.setOutTradeNo(order.getId());
request.setBizModel(model);
// 设置alipayClient
// 关闭2次
AlipayTradeCloseResponse execute = null;
if (isCertMode) {
execute = alipayClient.certificateExecute(request);
} else {
execute = alipayClient.execute(request);
}
if (!"40004".equals(execute.getCode())) {
return execute;
} else {
model.setOutTradeNo(order.getId() + "_1");
request.setBizModel(model);
if (isCertMode) {
execute = alipayClient.certificateExecute(request);
} else {
execute = alipayClient.execute(request);
}
if (!"40004".equals(execute.getCode())) {
return execute;
}
}
return null;
return execute;
}

public AlipayTradeRefundResponse refund(CommonOrder order) throws AlipayApiException {
AlipayTradeRefundRequest request = new AlipayTradeRefundRequest();
AlipayTradeRefundModel model = new AlipayTradeRefundModel();
model.setOutTradeNo(order.getId() + "_0");
model.setRefundAmount(order.getMixedPayAmount().toString());

if ("plan".equals(order.getType())) {
order.setId("p_".concat(order.getId()));
} else {
order.setId("t_".concat(order.getId()));
}

model.setOutTradeNo(order.getId());
model.setRefundAmount(order.getPayAmount().toString());
model.setOutRequestNo(order.getId() + "_" + RandomUtil.randomInt(100, 1000));
request.setBizModel(model);
AlipayTradeRefundResponse execute = null;
Expand All @@ -347,22 +336,6 @@ public AlipayTradeRefundResponse refund(CommonOrder order) throws AlipayApiExcep
} else {
execute = alipayClient.execute(request);
}
if (!"40004".equals(execute.getCode())) {
return execute;
} else {
model.setOutTradeNo(order.getId() + "_1");
model.setRefundAmount(order.getMixedPayAmount().toString());
model.setOutRequestNo(order.getId() + "_" + RandomUtil.randomInt(100, 1000));
request.setBizModel(model);
if (isCertMode) {
execute = alipayClient.certificateExecute(request);
} else {
execute = alipayClient.execute(request);
}
if (!"40004".equals(execute.getCode())) {
return execute;
}
}
return null;
return execute;
}
}
Loading

0 comments on commit c0befd2

Please sign in to comment.