comtikaweb 4 lat temu
rodzic
commit
e8d385c1ac

+ 33 - 0
ctkcloud-mybank-service/src/main/java/com/comtika/ctkcloud/server/constant/enums/ComtikaRegisterStatus.java

@@ -0,0 +1,33 @@
+/******************************************************************************
+ * Copyright (C) 2018 comtika Co.,Ltd
+ * All Rights Reserved.
+ * 本软件为康体佳智能科技(深圳)有限公司开发研制。未经本公司正式书面同意,其他任何个人、团体不得使用、
+ * 复制、修改或发布本软件.
+ *****************************************************************************/
+package com.comtika.ctkcloud.server.constant.enums;
+
+/**
+ * comtika服务商平台入驻状态
+ * @author 86151
+ *
+ */
+public enum ComtikaRegisterStatus {
+    EXAMINE(1, "入驻审核中"),
+    SUCCESS(2, "入驻成功"),
+    FAILURE(3, "入驻失败");
+    private int status;
+    private String text;
+
+    private ComtikaRegisterStatus(int status, String text) {
+        this.status = status;
+        this.text = text;
+    }
+
+    public int getStatus() {
+        return status;
+    }
+
+    public String getText() {
+        return text;
+    }
+}

+ 52 - 0
ctkcloud-mybank-service/src/main/java/com/comtika/ctkcloud/server/core/timer/ComtikaMyBankTimer.java

@@ -0,0 +1,52 @@
+package com.comtika.ctkcloud.server.core.timer;
+
+import java.util.List;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.scheduling.annotation.EnableScheduling;
+import org.springframework.scheduling.annotation.Scheduled;
+
+import com.comtika.ctkcloud.server.constant.enums.ComtikaRegisterStatus;
+import com.comtika.ctkcloud.server.dao.comtika.SysComtikaMerchantDao;
+import com.comtika.ctkcloud.server.entity.comtikawechat.SysComtikaMerchant;
+import com.comtika.ctkcloud.server.service.comtika.ComtikaMerchantService;
+
+
+@Configuration
+@EnableScheduling //康体佳定时器总开关
+public class ComtikaMyBankTimer {
+	
+	@Autowired
+	private ComtikaMerchantService comtikaMerchantService;
+	
+	@Autowired
+	private SysComtikaMerchantDao sysComtikaMerchantDao;
+	
+	/**
+	 * 定时任务,每天23点确认分账账单。防止未确认的存在数据库
+	 */
+	@Scheduled(cron ="0 0 23 * * ? ")
+	public void comtikaOrderNotice(){
+		comtikaMerchantService.comtikaOrderNotice();
+	}
+	
+	/**
+	 * 定时任务,每天5分钟查询入驻状态
+	 */
+	@Scheduled(cron ="0 0/5 * * * ? ")
+	public void queryWeChatRegisterMerchant(){
+		System.out.println("******开始查询入驻信息");
+		SysComtikaMerchant sysComtikaMerchant = new SysComtikaMerchant();
+		sysComtikaMerchant.setRegisterStatus(ComtikaRegisterStatus.EXAMINE.getStatus());
+		List<SysComtikaMerchant>list = sysComtikaMerchantDao.template(sysComtikaMerchant);
+		if(!list.isEmpty()){
+			for (SysComtikaMerchant sysComtikaMerchant2 : list) {
+				String businessCode = sysComtikaMerchant2.getBusinessCode();
+				comtikaMerchantService.queryWeChatRegisterMerchant(businessCode);
+			}
+			
+		}
+		
+	}
+}

+ 17 - 0
ctkcloud-mybank-service/src/main/java/com/comtika/ctkcloud/server/dao/comtika/SysComtikaMerchantDao.java

@@ -0,0 +1,17 @@
+package com.comtika.ctkcloud.server.dao.comtika;
+
+import java.util.Map;
+
+import com.comtika.ctkcloud.server.entity.comtikawechat.SysComtikaMerchant;
+
+import org.beetl.sql.core.annotatoin.SqlResource;
+import org.beetl.sql.core.mapper.BaseMapper;
+
+
+
+@SqlResource("comtika.merchant")
+public interface SysComtikaMerchantDao extends BaseMapper<SysComtikaMerchant> {
+
+	Map<String, Object> queryComtikaMerchant(Map<String, Object> map);
+
+}

+ 301 - 0
ctkcloud-mybank-service/src/main/java/com/comtika/ctkcloud/server/entity/comtikawechat/ComtikaRegisterMerchant.java

@@ -0,0 +1,301 @@
+package com.comtika.ctkcloud.server.entity.comtikawechat;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import com.comtika.ctkcloud.common.result.RespWrapper;
+import com.comtika.ctkcloud.common.util.StringUtil;
+import com.comtika.ctkcloud.server.constant.enums.ComtikaRegisterStatus;
+
+import lombok.Data;
+
+@Data
+public class ComtikaRegisterMerchant {
+
+	// 云平台商户ID
+	private Long merchantId;
+
+	// 申请业务单号
+	private String businessCode;
+
+	// 超级管理员姓名
+	private String contactName;
+
+	// 超级管理员身份证
+	private String contactIdNumber;
+
+	// 超级管理员手机号
+	private String contactPhone;
+
+	// 超级管理员邮箱
+	private String contactEmail;
+
+	// 主体类型
+	private String subjectType;
+
+	// 营业执照微信MediaID
+	private String subjectLicenseMediaID;
+
+	// 营业执照url
+	private String subjectLicenseUrl;
+
+	// 注册号/统一社会信用代码
+	private String licenseNumber;
+
+	// 商户名称
+	private String merchantName;
+
+	// 个体户经营者/法人姓名
+	private String legalPerson;
+
+	// 身份证类型
+	private String idDocType;
+
+	// 身份证人像面照片MediaID
+	private String idCardCopyMediaID;
+
+	// 身份证人像面照片URL
+	private String idCardCopyUrl;
+
+	// 身份证国徽面照片MediaID
+	private String idCardNationalMediaID;
+
+	// 身份证国徽面照片url
+	private String idCardNationalUrl;
+
+	// 身份证姓名
+	private String idCardName;
+
+	// 身份证号码
+	private String idCardNumber;
+
+	// 身份证有效期开始时间 示例值:2026-06-06
+	private String cardPeriodBegin;
+
+	// 身份证有效期结束时间 示例值:2026-06-06
+	private String cardPeriodEnd;
+
+	// 商户简称
+	private String merchantAbbr;
+
+	// 客服电话
+	private String servicePhone;
+
+	// 经营场景类型
+	private String salesType;
+	
+	private List<String> salesScenesType;
+
+	// 商家主体一致且已认证的小程序APPID
+	private String miniProgramSubAppid;
+	
+	//服务商小程序
+	private String miniProgramAppid;
+
+	// 小程序MediaID  用于存放上面的五个小程序MediaID
+	private List<String> miniProgramPicsMediaID;
+
+	//小程序图片url
+	private List<String> miniProgramPicsUrl;
+
+	// 结算规则id
+	private String settlementId;
+
+	// 请填写所属行业名称,详细参见费率结算规则对照表。
+	private String qualificationType;
+
+	/**
+	 * 1、若主体为企业/党政、机关及事业单位/其他组织,可填写:对公银行账户。 2、若主体为个体户,可选择填写:对公银行账户或经营者个人银行卡。
+	 * 枚举值:
+	 * 
+	 * BANK_ACCOUNT_TYPE_CORPORATE:对公银行账户 BANK_ACCOUNT_TYPE_PERSONAL:经营者个人银行卡
+	 * 示例值:BANK_ACCOUNT_TYPE_CORPORATE
+	 */
+	private String bankAccountType;
+
+	/**
+	 * 1、选择“经营者个人银行卡”时,开户名称必须与“经营者证件姓名”一致。 2、选择“对公银行账户”时,开户名称必须与营业执照上的“商户名称”一致。
+	 * 3、该字段需进行加密处理,加密方法详见敏感信息加密说明。 示例值:AOZdYGISxo4y4+kyblK2FCCqQJJp0/
+	 * 0eow96uY1Pk7Rq79Jtt7+I8juwEc4P4TG5xzchG/5IL9DBd+Z0zZXkw==
+	 */
+	private String accountName;
+
+	/**
+	 * 开户银行,详细参见开户银行对照表。 示例值:工商银行
+	 */
+	private String accountBank;
+
+	/**
+	 * 至少精确到市,详细参见省市区编号对照表。 示例值:110000
+	 */
+	private String bankAddressCode;
+
+	/**
+	 * 1、17家直连银行无需填写,如为其他银行,则开户银行全称(含支行)和开户银行联行号二选一。 2、详细参见开户银行全称(含支行)对照表。
+	 * 示例值:402713354941
+	 */
+	private String bankBranchId;
+
+	// 17家直连银行无需填写,如为其他银行,则开户银行全称(含支行)和 开户银行联行号二选一。
+	private String bankName;
+
+	// 银行卡号
+	private String accountNumber;
+
+	// 微信支付通知地址
+	private String notifyUrl;
+
+	public RespWrapper<Object> parameterValidation() {
+		if (StringUtil.isEmpty(this.contactName)) {
+			return RespWrapper.makeFailResp("超级管理员姓名不能为空!");
+		}
+		if (StringUtil.isEmpty(this.contactIdNumber)) {
+			return RespWrapper.makeFailResp("超级管理员身份证不能为空!");
+		}
+		if (StringUtil.isEmpty(this.contactPhone)) {
+			return RespWrapper.makeFailResp("超级管理员手机号不能为空!");
+		}
+		if (StringUtil.isEmpty(this.contactEmail)) {
+			return RespWrapper.makeFailResp("超级管理员邮箱不能为空!");
+		}
+		if (StringUtil.isEmpty(this.subjectType)) {
+			return RespWrapper.makeFailResp("主体类型不能为空!");
+		}
+		if (StringUtil.isEmpty(this.subjectLicenseMediaID)) {
+			return RespWrapper.makeFailResp("营业执照微信MediaID不能为空!");
+		}
+		if (StringUtil.isEmpty(this.subjectLicenseUrl)) {
+			return RespWrapper.makeFailResp("营业执照url不能为空!");
+		}
+		if (StringUtil.isEmpty(this.licenseNumber)) {
+			return RespWrapper.makeFailResp("注册号/统一社会信用代码不能为空!");
+		}
+		if (StringUtil.isEmpty(this.merchantName)) {
+			return RespWrapper.makeFailResp("商户名称不能为空!");
+		}
+		if (StringUtil.isEmpty(this.legalPerson)) {
+			return RespWrapper.makeFailResp("个体户经营者/法人姓名不能为空!");
+		}
+		if (StringUtil.isEmpty(this.idDocType)) {
+			return RespWrapper.makeFailResp("身份证类型不能为空!");
+		}
+		if (StringUtil.isEmpty(this.idCardCopyMediaID)) {
+			return RespWrapper.makeFailResp("身份证人像面照片MediaID不能为空!");
+		}
+		if (StringUtil.isEmpty(this.idCardCopyUrl)) {
+			return RespWrapper.makeFailResp("身份证人像面照片URL不能为空!");
+		}
+		if (StringUtil.isEmpty(this.idCardNationalMediaID)) {
+			return RespWrapper.makeFailResp("身份证国徽面照片MediaID不能为空!");
+		}
+		if (StringUtil.isEmpty(this.idCardNationalUrl)) {
+			return RespWrapper.makeFailResp("身份证国徽面照片url不能为空!");
+		}
+		if (StringUtil.isEmpty(this.idCardName)) {
+			return RespWrapper.makeFailResp("身份证姓名不能为空!");
+		}
+		if (StringUtil.isEmpty(this.cardPeriodBegin)) {
+			return RespWrapper.makeFailResp("身份证有效期开始时间不能为空!");
+		}
+		if (StringUtil.isEmpty(this.cardPeriodEnd)) {
+			return RespWrapper.makeFailResp("身份证有效期结束时间不能为空!");
+		}
+		if (StringUtil.isEmpty(this.merchantAbbr)) {
+			return RespWrapper.makeFailResp("商户简称不能为空!");
+		}
+		if (StringUtil.isEmpty(this.servicePhone)) {
+			return RespWrapper.makeFailResp("客服电话不能为空!");
+		}
+		if (StringUtil.isEmpty(this.settlementId)) {
+			return RespWrapper.makeFailResp("结算规则id不能为空!");
+		}
+		if (StringUtil.isEmpty(this.qualificationType)) {
+			return RespWrapper.makeFailResp("所属行业名称不能为空!");
+		}
+		if (StringUtil.isEmpty(this.bankAccountType)) {
+			return RespWrapper.makeFailResp("银行卡类型不能为空!");
+		}
+		if (StringUtil.isEmpty(this.accountName)) {
+			return RespWrapper.makeFailResp("开户名称不能为空!");
+		}
+		if (StringUtil.isEmpty(this.accountBank)) {
+			return RespWrapper.makeFailResp("开户银行不能为空!");
+		}
+		if (StringUtil.isEmpty(this.bankAddressCode)) {
+			return RespWrapper.makeFailResp("省市区编号不能为空!");
+		}
+		if (StringUtil.isEmpty(this.bankBranchId)
+				&& StringUtil.isEmpty(this.bankName)) {
+			return RespWrapper.makeFailResp("开户银行联行号或者开户银行全称(含支行)必须填写一个!");
+		}
+		if (StringUtil.isEmpty(this.accountNumber)) {
+			return RespWrapper.makeFailResp("银行卡号不能为空!");
+		}
+		return RespWrapper.makeSuccessResp("参数验证通过!");
+	}
+
+	
+
+	public void updateMerchant(SysComtikaMerchant sysComtikaMerchant,String businessCode2) {
+		//申请单号 - 用于查询入驻结果
+		sysComtikaMerchant.setBusinessCode(businessCode2);
+		sysComtikaMerchant.setMerchantId(this.merchantId);
+		sysComtikaMerchant.setBusinessCode(businessCode);
+		sysComtikaMerchant.setContactName(this.contactName);
+		sysComtikaMerchant.setContactIdNumber(this.contactIdNumber);
+		sysComtikaMerchant.setContactPhone(this.contactPhone);
+		sysComtikaMerchant.setContactEmail(this.contactEmail);
+		sysComtikaMerchant.setSubjectType(this.subjectType);
+		sysComtikaMerchant.setSubjectLicenseUrl(this.subjectLicenseUrl);
+		sysComtikaMerchant.setLicenseNumber(this.licenseNumber);
+		sysComtikaMerchant.setMerchantName(this.merchantName);
+		sysComtikaMerchant.setLegalPerson(this.legalPerson);
+		sysComtikaMerchant.setIdDocType(this.idDocType);
+		sysComtikaMerchant.setIdCardCopyUrl(this.idCardCopyUrl);
+		sysComtikaMerchant.setIdCardNationalUrl(this.idCardNationalUrl);
+		sysComtikaMerchant.setIdCardName(this.idCardName);
+		sysComtikaMerchant.setIdCardNumber(this.idCardNumber);
+		sysComtikaMerchant.setCardPeriodBegin(this.cardPeriodBegin);
+		sysComtikaMerchant.setCardPeriodEnd(this.cardPeriodEnd);
+		sysComtikaMerchant.setMerchantAbbr(this.merchantAbbr);
+		sysComtikaMerchant.setServicePhone(this.servicePhone);
+		sysComtikaMerchant.setSalesScenesType(this.salesType);
+		sysComtikaMerchant.setMiniProgramSubAppid(this.miniProgramSubAppid);
+		sysComtikaMerchant.setMiniProgramAppid(this.miniProgramAppid);
+		if(!this.miniProgramPicsUrl.isEmpty()){
+			if(this.miniProgramPicsUrl.size() >= 1){
+				sysComtikaMerchant.setMiniProgramPicsUrl1(this.miniProgramPicsUrl.get(0));
+			}
+			if(this.miniProgramPicsUrl.size() >= 2){
+				sysComtikaMerchant.setMiniProgramPicsUrl2(this.miniProgramPicsUrl.get(1));
+			}
+			if(this.miniProgramPicsUrl.size() >= 3){
+				sysComtikaMerchant.setMiniProgramPicsUrl3(this.miniProgramPicsUrl.get(2));
+			}
+			if(this.miniProgramPicsUrl.size() >= 4){
+				sysComtikaMerchant.setMiniProgramPicsUrl4(this.miniProgramPicsUrl.get(3));
+			}
+			if(this.miniProgramPicsUrl.size() >= 5){
+				sysComtikaMerchant.setMiniProgramPicsUrl5(this.miniProgramPicsUrl.get(4));
+			}
+		}
+		sysComtikaMerchant.setSettlementId(this.settlementId);
+		sysComtikaMerchant.setQualificationType(this.qualificationType);
+		sysComtikaMerchant.setBankAccountType(this.bankAccountType);
+		sysComtikaMerchant.setAccountName(this.accountName);
+		sysComtikaMerchant.setAccountBank(this.accountBank);
+		sysComtikaMerchant.setBankAddressCode(this.bankAddressCode);
+		sysComtikaMerchant.setBankName(this.bankName);
+		sysComtikaMerchant.setBankBranchId(this.bankBranchId);
+		sysComtikaMerchant.setAccountNumber(this.accountNumber);
+		sysComtikaMerchant.setRegisterStatus(ComtikaRegisterStatus.EXAMINE.getStatus());
+		sysComtikaMerchant.setRegisterMessage(ComtikaRegisterStatus.EXAMINE.getText());
+	}
+
+
+
+	public void updateSalesScenesType() {
+		this.salesScenesType = new ArrayList<String>();
+		this.salesScenesType.add(salesType);
+	}
+}

+ 173 - 0
ctkcloud-mybank-service/src/main/java/com/comtika/ctkcloud/server/entity/comtikawechat/SysComtikaMerchant.java

@@ -0,0 +1,173 @@
+package com.comtika.ctkcloud.server.entity.comtikawechat;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.GenerationType;
+import javax.persistence.Id;
+
+import lombok.Data;
+
+@Data
+@Entity
+public class SysComtikaMerchant {
+
+	@Id
+	@GeneratedValue(strategy = GenerationType.AUTO)
+	@Column(name = "id")
+	private Long id;
+
+	// 云平台商户ID
+	private Long merchantId;
+	
+	//服务商平台商户号
+	private String subMchId;
+	
+	// 申请业务单号
+	private String businessCode;
+
+	// 超级管理员姓名
+	private String contactName;
+
+	// 超级管理员身份证
+	private String contactIdNumber;
+
+	// 超级管理员手机号
+	private String contactPhone;
+
+	// 超级管理员邮箱
+	private String contactEmail;
+
+	// 主体类型
+	private String subjectType;
+
+	// 营业执照微信MediaID
+	private String subjectLicenseMediaID;
+
+	// 营业执照url
+	private String subjectLicenseUrl;
+
+	// 注册号/统一社会信用代码
+	private String licenseNumber;
+
+	// 商户名称
+	private String merchantName;
+
+	// 个体户经营者/法人姓名
+	private String legalPerson;
+
+	// 身份证类型
+	private String idDocType;
+
+	// 身份证人像面照片MediaID
+	private String idCardCopyMediaID;
+
+	// 身份证人像面照片URL
+	private String idCardCopyUrl;
+
+	// 身份证国徽面照片MediaID
+	private String idCardNationalMediaID;
+
+	// 身份证国徽面照片url
+	private String idCardNationalUrl;
+
+	// 身份证姓名
+	private String idCardName;
+
+	// 身份证号码
+	private String idCardNumber;
+
+	// 身份证有效期开始时间 示例值:2026-06-06
+	private String cardPeriodBegin;
+
+	// 身份证有效期结束时间 示例值:2026-06-06
+	private String cardPeriodEnd;
+
+	// 商户简称
+	private String merchantAbbr;
+
+	// 客服电话
+	private String servicePhone;
+
+	// 经营场景类型
+	private String salesScenesType;
+	
+	//服务商小程序
+	private String miniProgramAppid;
+	
+	// 商家主体一致且已认证的小程序APPID
+	private String miniProgramSubAppid;
+
+	// 小程序MediaID
+	private String miniProgramPicsMediaID1;
+
+	// 小程序MediaID
+	private String miniProgramPicsMediaID2;
+
+	// 小程序MediaID
+	private String miniProgramPicsMediaID3;
+
+	// 小程序MediaID
+	private String miniProgramPicsMediaID4;
+
+	// 小程序MediaID
+	private String miniProgramPicsMediaID5;
+
+	// 小程序图片url
+	private String miniProgramPicsUrl1;
+
+	// 小程序图片url
+	private String miniProgramPicsUrl2;
+
+	// 小程序图片url
+	private String miniProgramPicsUrl3;
+
+	// 小程序图片url
+	private String miniProgramPicsUrl4;
+
+	// 小程序图片url
+	private String miniProgramPicsUrl5;
+
+	// 结算规则id
+	private String settlementId;
+
+	// 请填写所属行业名称,详细参见费率结算规则对照表。
+	private String qualificationType;
+
+	/**
+	 * 1、若主体为企业/党政、机关及事业单位/其他组织,可填写:对公银行账户。 2、若主体为个体户,可选择填写:对公银行账户或经营者个人银行卡。
+	 * 枚举值:
+	 * 
+	 * BANK_ACCOUNT_TYPE_CORPORATE:对公银行账户 BANK_ACCOUNT_TYPE_PERSONAL:经营者个人银行卡
+	 * 示例值:BANK_ACCOUNT_TYPE_CORPORATE
+	 */
+	private String bankAccountType;
+
+	//开户名称
+	private String accountName;
+
+	//开户银行,详细参见开户银行对照表。 示例值:工商银行
+	private String accountBank;
+
+	//至少精确到市,详细参见省市区编号对照表。 示例值:110000
+	private String bankAddressCode;
+
+	/**
+	 * 1、17家直连银行无需填写,如为其他银行,则开户银行全称(含支行)和开户银行联行号二选一。 2、详细参见开户银行全称(含支行)对照表。
+	 * 示例值:402713354941
+	 */
+	private String bankBranchId;
+
+	// 17家直连银行无需填写,如为其他银行,则开户银行全称(含支行)和 开户银行联行号二选一。
+	private String bankName;
+
+	// 银行卡号
+	private String accountNumber;
+
+	// 入驻状态 1 审核中,2入驻成功,-1未入住
+	private Integer registerStatus;
+
+	// 入驻消息
+	private String registerMessage;
+
+}

+ 39 - 0
ctkcloud-mybank-service/src/main/java/com/comtika/ctkcloud/server/service/comtika/ComtikaMerchantService.java

@@ -0,0 +1,39 @@
+package com.comtika.ctkcloud.server.service.comtika;
+
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.web.multipart.MultipartFile;
+
+import com.comtika.ctkcloud.common.result.RespWrapper;
+import com.comtika.ctkcloud.server.entity.MybankPay;
+import com.comtika.ctkcloud.server.entity.comtikawechat.ComtikaRegisterMerchant;
+import com.comtika.ctkcloud.server.entity.order.CtkRechargeOrder;
+
+public interface ComtikaMerchantService {
+
+	RespWrapper<Object> weChatRegisterMerchant(ComtikaRegisterMerchant comtikaRegisterMerchant);
+
+	RespWrapper<Object> queryWeChatRegisterMerchant(String businessCode);
+
+	RespWrapper<Object> jsapiUnifiedOrder(MybankPay mybankPay, String ip,Long userId);
+
+	void notify(HttpServletResponse response, HttpServletRequest request);
+
+	RespWrapper<Object> comtikaPrePay(MybankPay mybankPay, Long userId,String ip);
+
+	RespWrapper<Object> refundComtika(Long rechargeOrderId,String payOrderId, Long refundAmount,Long merchantId,Long customerId);
+
+	RespWrapper<Object> comtikaOrderNotice(CtkRechargeOrder ctk);
+
+	void comtikaOrderNotice();
+
+	void queryComtikaRefund(Map<String, Object> map);
+
+	RespWrapper<Object> uploadPhoto(MultipartFile file);
+
+	RespWrapper<Object> queryMerchant(Long merchantId);
+
+}

+ 759 - 0
ctkcloud-mybank-service/src/main/java/com/comtika/ctkcloud/server/service/comtika/impl/ComtikaMerchantServiceImpl.java

@@ -0,0 +1,759 @@
+package com.comtika.ctkcloud.server.service.comtika.impl;
+
+import java.io.BufferedReader;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.web.multipart.MultipartFile;
+
+import com.alibaba.fastjson.JSONObject;
+import com.comtika.ctkcloud.common.bean.chargeserver.ChargeReqData;
+import com.comtika.ctkcloud.common.bean.order.RechargeOrder;
+import com.comtika.ctkcloud.common.enums.chargerserver.ChargerPayModle;
+import com.comtika.ctkcloud.common.enums.mybank.MyBankRefundType;
+import com.comtika.ctkcloud.common.enums.pay.OrderStatusEnum;
+import com.comtika.ctkcloud.common.result.RespCode;
+import com.comtika.ctkcloud.common.result.RespWrapper;
+import com.comtika.ctkcloud.common.util.IDUtil;
+import com.comtika.ctkcloud.common.util.StringUtil;
+import com.comtika.ctkcloud.server.base.UnifyPayModel;
+import com.comtika.ctkcloud.server.core.ComtikaHttpsUtil;
+import com.comtika.ctkcloud.server.dao.comtika.SysComtikaMerchantDao;
+import com.comtika.ctkcloud.server.dao.pay.PrePayDao;
+import com.comtika.ctkcloud.server.dao.refund.RefundDao;
+import com.comtika.ctkcloud.server.dao.sepAccount.ReceiveDao;
+import com.comtika.ctkcloud.server.entity.DaFeng;
+import com.comtika.ctkcloud.server.entity.MybankPay;
+import com.comtika.ctkcloud.server.entity.comtikawechat.ComtikaRegisterMerchant;
+import com.comtika.ctkcloud.server.entity.comtikawechat.SysComtikaMerchant;
+import com.comtika.ctkcloud.server.entity.mybank.CtkRefund;
+import com.comtika.ctkcloud.server.entity.order.CtkRechargeOrder;
+import com.comtika.ctkcloud.server.entity.sepAccount.CtkReceiveUser;
+import com.comtika.ctkcloud.server.fegin.CustomerService;
+import com.comtika.ctkcloud.server.fegin.OrderNoFeignService;
+import com.comtika.ctkcloud.server.fegin.ServerFeignService;
+import com.comtika.ctkcloud.server.service.comtika.ComtikaMerchantService;
+import com.comtika.ctkcloud.server.util.dafeng.Base64Utils;
+import com.comtika.ctkcloud.server.util.dafeng.RSAUtils;
+import com.comtika.ctkcloud.server.util.http.HTTPUtils;
+@Service
+public class ComtikaMerchantServiceImpl implements ComtikaMerchantService {
+
+	@Autowired
+	private SysComtikaMerchantDao sysComtikaMerchantDao;
+
+	@Autowired
+	private PrePayDao prePayDao;
+
+	@Autowired
+	private ServerFeignService serverFeignService;
+
+	@Autowired
+	private OrderNoFeignService orderNoFeignService;
+
+	@Autowired
+	private CustomerService customerService;
+
+	@Autowired
+	private RefundDao refundDao;
+	
+	@Autowired
+    private ReceiveDao receiveDao;
+
+	//public static String host = "http://127.0.0.1:8888";
+	public static String host = "https://www.comtikaiot.cn/wechatpay";
+	
+	public static String weChatRegisterMerchant = "/merchant/weChatRegisterMerchant";
+
+	public static String queryWeChatRegisterMerchant = "/merchant/queryWeChatRegisterbyBusinessCode";
+
+	public static String unifiedOrder = "/wxpay/jsapi/unifiedOrder";
+	
+	public static String wxRefund = "/wxpay/jsapi/refund";
+	
+	public static String queryRefund = "/wxpay/jsapi/queryRefundByOutOrderNo";
+	
+	public static String upload = "/photo/weChatUpload";
+	
+	public static String notifyUrl = "https://www.comtikaiot.cn/api/zuul/mybank/comtika/notify";
+	
+
+	@SuppressWarnings("unchecked")
+	@Override
+	public RespWrapper<Object> weChatRegisterMerchant(
+			ComtikaRegisterMerchant comtikaRegisterMerchant) {
+		try {
+			// 参数验证
+			RespWrapper<Object> data = comtikaRegisterMerchant
+					.parameterValidation();
+			if (RespCode.SUCCESS != data.getCode()) {
+				return data;
+			}
+			// 给经营场景赋值
+			comtikaRegisterMerchant.updateSalesScenesType();
+			//赋值支付回调地址
+			comtikaRegisterMerchant.setNotifyUrl(notifyUrl);
+			// 获取请求头
+			Map<String, String> map = requestHeader();
+			String body = JSONObject.toJSONString(comtikaRegisterMerchant);
+			// 调用商户入驻
+			// String httpData =
+			// "{\"code\":0,\"msg\":\"\",\"data\":{\"businessCode\":\"Comtika_454B512D2EDC4F0596D1223CACD99DF51587975799\"},\"success\":true}";
+			String httpData = HTTPUtils.post(host + weChatRegisterMerchant,map, body);
+			RespWrapper<Object> respWrapper = JSONObject.parseObject(httpData,RespWrapper.class);
+			if (RespCode.SUCCESS != respWrapper.getCode()) {
+				return respWrapper;
+			}
+			JSONObject jsonObject = JSONObject.parseObject(respWrapper.getData().toString());
+			String businessCode = String.valueOf(jsonObject.get("businessCode"));
+			SysComtikaMerchant sysComtikaMerchant = new SysComtikaMerchant();
+			// 给数据库实体对象赋值
+			comtikaRegisterMerchant.updateMerchant(sysComtikaMerchant,businessCode);
+			sysComtikaMerchantDao.insert(sysComtikaMerchant);
+		} catch (Exception e) {
+			e.printStackTrace();
+			return RespWrapper.makeErrorResp("服务器错误");
+		}
+		return RespWrapper.makeSuccessResp("商户入驻成功!");
+	}
+
+	@SuppressWarnings("unchecked")
+	@Override
+	public RespWrapper<Object> queryWeChatRegisterMerchant(String businessCode) {
+		try {
+			if (StringUtil.isEmpty(businessCode)) {
+				return RespWrapper.makeFailResp("请求参数有误,请检查!");
+			}
+			SysComtikaMerchant sysComtikaMerchant = new SysComtikaMerchant();
+			sysComtikaMerchant.setBusinessCode(businessCode);
+			sysComtikaMerchant = sysComtikaMerchantDao.templateOne(sysComtikaMerchant);
+			if (null == sysComtikaMerchant) {
+				return RespWrapper.makeFailResp("申请单号不存在,请检查!");
+			}
+			if (sysComtikaMerchant.getRegisterStatus() == 2) {
+				String msg = "已经入驻成功!";
+				Integer registerStatus = sysComtikaMerchant.getRegisterStatus();
+				Map<String, Object> map = new HashMap<String, Object>();
+				map.put("msg", msg);
+				map.put("registerStatus", registerStatus);
+				return RespWrapper.makeSuccessResp(map);
+			}
+			// 获取请求头
+			Map<String, String> map = requestHeader();
+			// 将businessCode生成json数据
+			Map<String, String> json = new HashMap<String, String>();
+			json.put("businessCode", businessCode);
+			String body = JSONObject.toJSONString(json);
+			System.out.println(body);
+			// 请求服务商平台
+			String httpData = HTTPUtils.post(host + queryWeChatRegisterMerchant, map, body);
+			RespWrapper<Object> respWrapper = JSONObject.parseObject(httpData,RespWrapper.class);
+			if (RespCode.SUCCESS != respWrapper.getCode()) {
+				return respWrapper;
+			}
+			JSONObject jsonObject = JSONObject.parseObject(respWrapper.getData().toString());
+			String subMchid = jsonObject.getString("subMchid");
+			Integer registerStatus = jsonObject.getInteger("registerStatus");
+			String registerMessage = jsonObject.getString("registerMessage");
+			sysComtikaMerchant.setSubMchId(subMchid);
+			sysComtikaMerchant.setRegisterStatus(registerStatus);
+			sysComtikaMerchant.setRegisterMessage(registerMessage);
+			sysComtikaMerchantDao.updateTemplateById(sysComtikaMerchant);
+		} catch (Exception e) {
+			e.printStackTrace();
+			return RespWrapper.makeErrorResp("服务器错误!");
+		}
+		return RespWrapper.makeSuccessResp("");
+	}
+
+	@Override
+	public RespWrapper<Object> jsapiUnifiedOrder(MybankPay mybankPay,
+			String ip, Long userId) {
+		try {
+			String openId = null;
+			// 获取支付类型
+			UnifyPayModel payModel = UnifyPayModel
+					.valueOf(UnifyPayModel.ONLINE_PAY.getId());
+			String profitSharing = "Y";// 由于是在线支付,默认都是分账的
+			Long startTime = System.currentTimeMillis();
+			Map<String, Object> map = new HashMap<String, Object>();
+			map.put("streamNo", mybankPay.getStreamNo());
+			map = sysComtikaMerchantDao.queryComtikaMerchant(map);
+			Integer registerStatus = Integer.parseInt(map.get("registerStatus")
+					+ "");
+			if (registerStatus == null || registerStatus != 2) {
+				return RespWrapper.makeErrorResp("商户未入住,请联系商户!");
+			}
+			CtkRechargeOrder order = new CtkRechargeOrder();
+			order.setGoodsName("充电" + mybankPay.getTotalFee() * 1.0 / 100 + "元");
+			// 在线充电需要关联至商户
+			order.setMerchantId(Long
+					.parseLong(map.get("merchantId").toString()));
+			// 2分中支付时间 过期时间
+			order.setInvalidTime(startTime + 2 * 1000 * 60);
+			order.setCreateTime(startTime);
+			order.setCustomerId(userId);
+			String merchantNo = map.get("subMchid").toString();
+			// 生成充值订单
+			addRechargeOrder(userId, mybankPay, payModel, order);
+			ChargeReqData chargeReqData = new ChargeReqData();
+			// 生成充电订单
+			addChargeReqData(chargeReqData, mybankPay, order);
+			chargeReqData.setRechargeNo(order.getId());
+			chargeReqData.setUserId(userId);
+			System.out.println("参数内容:" + chargeReqData.toString());
+			RespWrapper<String> startCharge = serverFeignService
+					.startCharge(chargeReqData);
+			if (!startCharge.isSuccess())
+				return RespWrapper.makeFailResp(startCharge.getMsg());
+			// 获取支付人 openId
+			RespWrapper<Map<String, Object>> customer = customerService
+					.queryCustomerById(userId);
+			if (!customer.isSuccess())
+				return RespWrapper.makeFailResp(customer.getMsg());
+			openId = customer.getData().get("openId").toString();
+			RespWrapper<Object> orderData = null;
+			try {
+				orderData = toPaymentApply(openId, ip, mybankPay.getTotalFee(),
+						profitSharing, order.getOrderId(),
+						order.getGoodsName(), merchantNo);
+				if (!orderData.isSuccess())
+					return RespWrapper.makeFailResp(orderData.getMsg());
+			} catch (Exception e) {
+				e.printStackTrace();
+				return RespWrapper.makeErrorResp("调用微信支付失败,请联系管理员!");
+			}
+			return RespWrapper.makeSuccessResp(orderData.getData());
+		} catch (Exception e) {
+			e.printStackTrace();
+			return RespWrapper.makeErrorResp("服务器错误,请重试!");
+		}
+
+	}
+
+	@SuppressWarnings("unchecked")
+	private RespWrapper<Object> toPaymentApply(String openId, String ip,
+			Long totalFee, String profitSharing, String orderId,
+			String goodsName, String merchantNo) throws Exception {
+		Map<String, Object> condition = new HashMap<>(7);
+		condition.put("profitSharing", profitSharing);
+		condition.put("subOpenid", openId);
+		condition.put("totalFee", totalFee);
+		condition.put("outOrderNo", orderId);
+		condition.put("body", goodsName);
+		condition.put("spbillCreateIp", ip);
+		condition.put("subMchid", merchantNo);
+		String url = host + unifiedOrder;
+		String httpData = ComtikaHttpsUtil.doPost(url,
+				JSONObject.toJSONString(condition));
+		RespWrapper<Object> data = JSONObject.parseObject(httpData,
+				RespWrapper.class);
+		return data;
+	}
+
+	private void addChargeReqData(ChargeReqData chargeReqData,
+			MybankPay mybankPay, CtkRechargeOrder order) {
+		chargeReqData.setStreamNo(mybankPay.getStreamNo());
+		chargeReqData.setChargerMode(mybankPay.getChargerMode());
+		chargeReqData.setChargerValue(mybankPay.getChargerValue());
+		chargeReqData.setTotalFee(mybankPay.getTotalFee());
+		chargeReqData.setFormId(mybankPay.getFormId());
+		ChargerPayModle payType = mybankPay.getPayType() == 1 ? ChargerPayModle.WX_ONLINE
+				: ChargerPayModle.ALI_ONLIEN;
+		chargeReqData.setPayType(payType.getId());
+		Integer overdue = (int) (order.getInvalidTime() / 60 / 1000);
+		chargeReqData.setOverdue(overdue);
+	}
+
+	/**
+	 * 新增充值订单
+	 * 
+	 * @param userId
+	 * @param mybankPay
+	 * @param payModel
+	 * @param order
+	 * @return
+	 */
+	public void addRechargeOrder(Long userId, MybankPay mybankPay,
+			UnifyPayModel payModel, CtkRechargeOrder order) {
+		// 生成对应订单编号
+		String orderNo = IDUtil.prePayID(mybankPay.getPayType(),
+				payModel.getModeName());
+		// 支付状态
+		order.setStatus(OrderStatusEnum.UN_PAY.getId());
+		// 订单金额
+		order.setGoodsId(mybankPay.getTotalFee());
+		// 订单编号
+		order.setOrderId(orderNo);
+		// 充值模式 在线、余额、智能卡
+		order.setPayModel(payModel.getId());
+		// 支付类型
+		order.setPayType(mybankPay.getPayType());
+		order.setRemark(payModel.getBoby());
+		order.setTotalFee(mybankPay.getTotalFee());
+		// 设置支付渠道,1-网商,2-大风,3-康体佳服务商平台
+		order.setChannelType(3);
+		// 大风发起支付,那么先把订单设置成未确认分账
+		order.setDaFengStatus(0);
+		// order.setCustomerId(userId);
+		// 获取当前充值订单表的id,如果是在线充电,需要把充值订单表的id传递给充电订单服务模块
+		prePayDao.insertTemplate(order, true);
+	}
+
+	public static Map<String, String> requestHeader() {
+		Map<String, String> map = new HashMap<String, String>();
+		map.put("Charsert", "UTF-8");
+		map.put("connection", "Keep-Alive");
+		map.put("Content-Type", "application/json");
+		map.put("Accept", "application/json");
+		return map;
+	}
+
+	public static void main(String[] args) {
+		/*
+		 * ComtikaRegisterMerchant comtikaRegisterMerchant = new
+		 * ComtikaRegisterMerchant(); comtikaRegisterMerchant.setMerchantId(1L);
+		 * comtikaRegisterMerchant.setContactName("1");
+		 * comtikaRegisterMerchant.setContactIdNumber("1");
+		 * comtikaRegisterMerchant.setContactPhone("1");
+		 * comtikaRegisterMerchant.setContactEmail("1");
+		 * comtikaRegisterMerchant.setSubjectType("1");
+		 * comtikaRegisterMerchant.setSubjectLicenseMediaID("1");
+		 * comtikaRegisterMerchant.setSubjectLicenseUrl("1");
+		 * comtikaRegisterMerchant.setLicenseNumber("1");
+		 * comtikaRegisterMerchant.setMerchantName("1");
+		 * comtikaRegisterMerchant.setLegalPerson("1");
+		 * comtikaRegisterMerchant.setIdDocType("1");
+		 * comtikaRegisterMerchant.setIdCardCopyMediaID("1");
+		 * comtikaRegisterMerchant.setIdCardCopyUrl("1");
+		 * comtikaRegisterMerchant.setIdCardNationalMediaID("1");
+		 * comtikaRegisterMerchant.setIdCardNationalUrl("1");
+		 * comtikaRegisterMerchant.setIdCardName("1");
+		 * comtikaRegisterMerchant.setIdCardNumber("1");
+		 * comtikaRegisterMerchant.setCardPeriodBegin("1");
+		 * comtikaRegisterMerchant.setCardPeriodEnd("1");
+		 * comtikaRegisterMerchant.setMerchantAbbr("1");
+		 * comtikaRegisterMerchant.setServicePhone("1");
+		 * comtikaRegisterMerchant.setSalesType("SALES_SCENES_MINI_PROGRAM");
+		 * comtikaRegisterMerchant.setMiniProgramSubAppid("1"); List<String> str
+		 * = new ArrayList<String>(); str.add("1");
+		 * comtikaRegisterMerchant.setMiniProgramPicsMediaID(str);
+		 * comtikaRegisterMerchant.setMiniProgramPicsUrl(str);
+		 * comtikaRegisterMerchant.setSettlementId("1");
+		 * comtikaRegisterMerchant.setQualificationType("1");
+		 * comtikaRegisterMerchant
+		 * .setBankAccountType("BANK_ACCOUNT_TYPE_CORPORATE");
+		 * comtikaRegisterMerchant.setAccountName("1");
+		 * comtikaRegisterMerchant.setAccountBank("1");
+		 * comtikaRegisterMerchant.setBankAddressCode("1");
+		 * comtikaRegisterMerchant.setBankBranchId("1");
+		 * comtikaRegisterMerchant.setBankName("1");
+		 * comtikaRegisterMerchant.setAccountNumber("1");
+		 * comtikaRegisterMerchant.setNotifyUrl("1"); ComtikaMerchantServiceImpl
+		 * a = new ComtikaMerchantServiceImpl(); System.out.println(new Date());
+		 * System
+		 * .out.println(a.weChatRegisterMerchant(comtikaRegisterMerchant));
+		 * System.out.println(new Date());
+		 */
+
+		ComtikaMerchantServiceImpl a = new ComtikaMerchantServiceImpl();
+		a.queryWeChatRegisterMerchant("111");
+	}
+
+	@Override
+	public void notify(HttpServletResponse response, HttpServletRequest request) {
+		try {
+			String transactionId = request.getParameter("transactionId");
+			String subMchid = request.getParameter("subMchid");
+			String outTradeNo = request.getParameter("outTradeNo");
+			String payTime = request.getParameter("payTime");
+			/** 根据订单编号到数据库查询唯一订单信息 **/
+			RespWrapper<RechargeOrder> data = orderNoFeignService
+					.queryUniqOrderByOrderId(outTradeNo);
+			Integer payModel = null;
+			Boolean flag = false;
+			if (data.isSuccess()) {
+				/** 判断该订单是什么类型,0-在线充电,1-余额充值,2-智能卡充值 **/
+				// 只做在线充电的
+				payModel = data.getData().getPayModel();
+				if (payModel == 0) {
+					RespWrapper<Object> object = orderNoFeignService
+							.myBankNotifyOrder(outTradeNo, data.getData()
+									.getTotalfee(), transactionId);
+					flag = object.isSuccess();
+				}
+				if (flag) {
+					Map<String, Object> map = new HashMap<String, Object>();
+					map.put("respCode", "0000");
+					map.put("respMsg", "回调成功!");
+					map.put("code", "SUCCESS");
+					String json = JSONObject.toJSONString(map);
+					response.setContentType("application/json;charset=UTF-8");
+					response.getWriter().write(json);
+				}
+				if (payModel != null && payModel == 0 && flag) {
+					/**
+					 * 此部分为在线充电,调用下发充电接口.因为开启充电时间比较长。所以先返回给网商,再下发充电..不管开启失败,
+					 * 失败会在订单服务退款
+					 **/
+					System.out.println("id的参数为:" + data.getData().getId());
+					RespWrapper<Boolean> bl = serverFeignService
+							.onlinePayStartCharger(data.getData().getId());
+					System.out.println(bl.getMsg());
+				}
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+
+	}
+
+	@Override
+	public RespWrapper<Object> comtikaPrePay(MybankPay mybankPay, Long userId,
+			String ip) {
+		try {
+			if (mybankPay == null)
+				return RespWrapper.makeFailResp("入参不能为空");
+			if (mybankPay.getTotalFee() < 0)
+				return RespWrapper.makeFailResp("支付金额不能小于最小值");
+			System.out.println("入参:" + mybankPay.toString());
+			// String merchantNo = null;
+			// 查询康体佳的商户号
+			SysComtikaMerchant comtika = new SysComtikaMerchant();
+			comtika.setMerchantId(1L);
+			comtika.setRegisterStatus(2);
+			comtika = sysComtikaMerchantDao.templateOne(comtika);
+			if (comtika == null) {
+				return RespWrapper.makeFailResp("暂时不支持余额充值,请联系管理员!");
+			}
+			Long startTime = System.currentTimeMillis();
+			// 获取支付类型
+			UnifyPayModel payModel = UnifyPayModel.valueOf(mybankPay
+					.getPayModel());
+			CtkRechargeOrder order = new CtkRechargeOrder();
+			// 如果不是在线充电,订单关联到康体佳
+			order.setMerchantId(1L);
+			order.setCustomerId(userId);
+			order.setCreateTime(startTime);
+			// 30分中支付时间 过期时间
+			order.setInvalidTime(startTime + 30 * 1000 * 60);
+			order.setGoodsName("充值" + mybankPay.getTotalFee() * 1.0 / 100 + "元");
+			if (payModel == UnifyPayModel.CARD_PAY) {
+				/** 此部分为智能卡业务 **/
+				if (mybankPay.getId() != null
+						&& userId.longValue() != mybankPay.getId()) {
+					order.setGoodsName("他人充值" + mybankPay.getTotalFee() * 1.0
+							/ 100 + "元");
+					// 智能卡被充值人id
+					order.setCustomerId(mybankPay.getId());
+				}
+			}
+			// 获取支付人 openId
+			RespWrapper<Map<String, Object>> customer = customerService
+					.queryCustomerById(userId);
+			if (!customer.isSuccess())
+				return RespWrapper.makeFailResp(customer.getMsg());
+			// 生成订单
+			addRechargeOrder(userId, mybankPay, payModel, order);
+			String openId = customer.getData().get("openId").toString();
+			// 站点id默认1L
+			return toPaymentApply(openId, ip, mybankPay.getTotalFee(), "N",
+					order.getOrderId(), order.getGoodsName(),
+					comtika.getSubMchId());
+		} catch (Exception e) {
+			e.printStackTrace();
+			return RespWrapper.makeErrorResp("服务器错误!");
+		}
+
+	}
+
+	@Override
+	public RespWrapper<Object> refundComtika(Long rechargeOrderId,
+			String payOrderId, Long refundAmount, Long merchantId,
+			Long customerId) {
+		try {
+			String refundFlowId = "comtika_tui_"+ System.currentTimeMillis();
+			// 生成退款表数据
+			CtkRefund ctkRefund = new CtkRefund();
+			ctkRefund.setOutRefundNo(refundFlowId);
+			ctkRefund.setMerchantId(merchantId);
+			ctkRefund.setRechargeOrderId(rechargeOrderId);
+			ctkRefund.setRefundFee(refundAmount);
+			ctkRefund.setCreateTime(System.currentTimeMillis());
+			ctkRefund.setChannelType(3);
+			ctkRefund.setCustomerId(customerId);
+			refundDao.insert(ctkRefund, true);
+			
+			SysComtikaMerchant comtika = new SysComtikaMerchant();
+			comtika.setMerchantId(ctkRefund.getMerchantId());
+			comtika.setRegisterStatus(2);
+			comtika = sysComtikaMerchantDao.templateOne(comtika);
+			String refundDesc =  "结束充电";
+			// 发起退款
+			RespWrapper<Object> result = refund(refundAmount,refundDesc,payOrderId,refundFlowId,comtika.getSubMchId());
+			JSONObject json = JSONObject.parseObject(result.getData().toString());
+			if (result.isSuccess()) {
+				ctkRefund.setStatus(MyBankRefundType.ACCEPTANCE.getId());
+				//康体佳服务商平台受理成功返回的单号
+				String refundOrderId = json.getString("refundId");
+				ctkRefund.setRefundOrderNo(refundOrderId);
+				ctkRefund.setRefundMsg("康体佳服务商平台受理成功");
+				refundDao.updateTemplateById(ctkRefund);
+				return RespWrapper.makeSuccessResp("发起退款成功!");
+			} else {
+				ctkRefund.setStatus(MyBankRefundType.FAIRLY.getId());// 康体佳服务商平台受理失败
+				if (json.get("respMsg") != null) {
+					ctkRefund.setRefundMsg(String.valueOf(json.get("respMsg")));
+				}
+				refundDao.updateTemplateById(ctkRefund);
+				return RespWrapper.makeFailResp("退款失败,失败原因:"+ ctkRefund.getRefundMsg());
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return null;
+	}
+
+	@SuppressWarnings("unchecked")
+	private RespWrapper<Object> refund(Long refundAmount, String refundDesc,
+			String payOrderId, String refundFlowId, String subMchId) throws Exception {
+		Map<String,Object> map = new HashMap<String, Object>();
+		map.put("refundFee", refundAmount);
+		map.put("refundDesc", refundDesc);
+		map.put("transactionId", payOrderId);
+		map.put("outRefundNo", refundFlowId);
+		map.put("subMchid", subMchId);
+		String str = ComtikaHttpsUtil.doPost(host + wxRefund, JSONObject.toJSONString(map));
+		RespWrapper<Object> data = JSONObject.parseObject(str,RespWrapper.class);
+		return data;
+	}
+	/**
+	 * 康体佳服务商平台订单确认发起分账
+	 */
+	@SuppressWarnings("unchecked")
+	@Override
+	public RespWrapper<Object> comtikaOrderNotice(CtkRechargeOrder ctk) {
+		try {
+			Map<String,Object> map = new HashMap<String, Object>();
+			map.put("rechargeOrderId", ctk.getId());
+			//根据充值订单id到充电订单查询站点id和商户id
+			map = prePayDao.queryRechargeOrderSiteIdAndMerchantId(map);
+			Long merchantId = Long.parseLong(map.get("merchantId")+"");
+			SysComtikaMerchant sys= new SysComtikaMerchant();
+			sys.setMerchantId(merchantId);
+			//查询康体佳服务商平台商户号
+			sys = sysComtikaMerchantDao.templateOne(sys);
+			CtkReceiveUser ck = new CtkReceiveUser();
+			Integer siteId = Integer.parseInt(map.get("siteId")+"");
+			ck.setSiteId(siteId);
+			ck.setMerchantId(Integer.parseInt(merchantId+""));
+			ck = receiveDao.templateOne(ck);
+			map.clear();
+			map.put("subMchId", sys.getSubMchId());
+			map.put("transactionId", ctk.getPayTransactionId());
+			map.put("groupName", ck.getGroupName());
+			String str = ComtikaHttpsUtil.doPost(ctk.getPayTransactionId(), JSONObject.toJSONString(map));
+			RespWrapper<Object> data = JSONObject.parseObject(str, RespWrapper.class);
+			if(data.isSuccess()){
+				CtkRechargeOrder cro = new CtkRechargeOrder();
+				cro.setId(ctk.getId());
+				cro.setDaFengStatus(1);
+				//如果是分账成功,需要修改订单的状态
+				prePayDao.updateTemplateById(cro);
+			}
+			return RespWrapper.makeSuccessResp("分账成功!");
+		} catch (Exception e) {
+			e.printStackTrace();
+			return RespWrapper.makeErrorResp("服务器错误!");
+		}
+		
+	}
+
+	@Override
+	public void comtikaOrderNotice() {
+		try {
+			//1.查找大风在线支付订单,支付成功,并且订单未确认的..
+			List<Map<String,Object>> list = prePayDao.queryComtikaOrder();
+			for (Map<String, Object> map : list) {
+				//充电预付金额
+				Long chargeMoney = map.get("chargeMoney") == null? 0L : Long.parseLong(String.valueOf(map.get("chargeMoney")));
+				//充电结算金额
+				Long totalFee = map.get("totalFee") == null? 0L : Long.parseLong(String.valueOf(map.get("totalFee")));
+				//充值订单id
+				Long rechargeNo = Long.parseLong(String.valueOf(map.get("rechargeNo")));
+				
+				
+				if( chargeMoney.equals(totalFee) ){
+					//如果两个金额相等,那么就是没有退款,就需要向康体佳服务商平台确认订单可以分账
+					CtkRechargeOrder ctk = new CtkRechargeOrder();
+					ctk.setId(rechargeNo);
+					ctk = prePayDao.templateOne(ctk);
+					comtikaOrderNotice(ctk);
+				}else{
+					//如果两个金额不相等,就去查询退款表,看是否退款成功
+					CtkRefund ctkRefund = new CtkRefund();
+					ctkRefund.setRechargeOrderId(rechargeNo);
+					ctkRefund.setStatus(1);
+					ctkRefund = refundDao.templateOne(ctkRefund);
+					if(ctkRefund != null){
+						//comtikaOrderNotice(rechargeNo);
+					}
+				}
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+	@SuppressWarnings("unchecked")
+	@Override
+	public void queryComtikaRefund(Map<String, Object> map) {
+		try {
+			Integer status = Integer.parseInt(map.get("status").toString());
+			Long id = Long.parseLong(String.valueOf(map.get("id")));
+			Long merchantId = Long.parseLong(map.get("merchantId")+""); 
+			Long rechargeOrderId = Long.parseLong(String.valueOf(map.get("rechargeOrderId")));
+			Long refundFee = Long.parseLong(String.valueOf(map.get("refundFee")));
+			CtkRefund ctkRefund = new CtkRefund();
+			ctkRefund.setId(id);
+			if(status == MyBankRefundType.ACCEPTANCE.getId() || status == MyBankRefundType.REFUNDING.getId()){
+				//退款中和受理成功,需要重新发起查询
+				String refundOrderNo = String.valueOf(map.get("refundOrderNo"));
+				if(StringUtil.isEmpty(refundOrderNo))return;
+				Map<String, Object> mapData = new HashMap<String, Object>();
+				mapData.put("refundId", refundOrderNo);
+				String url = host + queryRefund;
+				String str = ComtikaHttpsUtil.doPost(url, JSONObject.toJSONString(mapData));
+				RespWrapper<Object> data = JSONObject.parseObject(str,RespWrapper.class);
+				if(data.isSuccess()){
+					JSONObject json = JSONObject.parseObject(data.getData()+"");
+					Integer refundStatus = json.getInteger("refundStatus");
+					Long refundSuccessTime = null;
+					String refundMessage = json.getString("refundMessage");;
+					if(refundStatus == 1){ //退款成功
+						refundStatus = MyBankRefundType.SUCC.getId();
+						refundSuccessTime = json.getLong("refundSuccessTime");
+					}else if(refundStatus == 2){//退款处理中
+						refundStatus = MyBankRefundType.REFUNDING.getId();
+					}else if(refundStatus == 3 || refundStatus == 4){//退款失败
+						refundStatus = MyBankRefundType.FAIL.getId();
+					}
+					ctkRefund.setStatus(refundStatus);
+					ctkRefund.setGmtRefundment(refundSuccessTime);
+					ctkRefund.setRefundMsg(refundMessage);
+					refundDao.updateTemplateById(ctkRefund);
+					//退款成功后,发起分账
+					if(refundStatus == 1){
+						CtkRechargeOrder ctk = new CtkRechargeOrder();
+						ctk.setId(rechargeOrderId);
+						ctk = prePayDao.templateOne(ctk);
+						Map<String,Object> map1 = new HashMap<String, Object>();
+						map1.put("rechargeOrderId",rechargeOrderId);
+						//根据充值订单id到充电订单查询站点id和商户id
+						map1 = prePayDao.queryRechargeOrderSiteIdAndMerchantId(map1);
+						SysComtikaMerchant sys= new SysComtikaMerchant();
+						sys.setMerchantId(merchantId);
+						//查询康体佳服务商平台商户号
+						sys = sysComtikaMerchantDao.templateOne(sys);
+						CtkReceiveUser ck = new CtkReceiveUser();
+						Integer siteId = Integer.parseInt(map1.get("siteId")+"");
+						ck.setSiteId(siteId);
+						ck.setMerchantId(Integer.parseInt(merchantId+""));
+						ck = receiveDao.templateOne(ck);
+						map1.clear();
+						map1.put("subMchId", sys.getSubMchId());
+						map1.put("transactionId", ctk.getPayTransactionId());
+						map1.put("groupName", ck.getGroupName());
+						map1.put("amount", ctk.getTotalFee() - refundFee);//分账金额等于总金额减去退款金额
+						String str1 = ComtikaHttpsUtil.doPost(ctk.getPayTransactionId(), JSONObject.toJSONString(map));
+						RespWrapper<Object> data1 = JSONObject.parseObject(str1, RespWrapper.class);
+						if(data1.isSuccess()){
+							CtkRechargeOrder cro = new CtkRechargeOrder();
+							cro.setId(ctk.getId());
+							cro.setDaFengStatus(1);
+							//如果是分账成功,需要修改订单的状态
+							prePayDao.updateTemplateById(cro);
+						}
+					}
+				}
+			}else{
+				CtkRechargeOrder cro = new CtkRechargeOrder();
+				cro.setId(rechargeOrderId);
+				cro = prePayDao.templateOne(cro);
+				String refundFlowId = "comtika_tui_"+ System.currentTimeMillis();
+				ctkRefund = refundDao.templateOne(ctkRefund);
+				SysComtikaMerchant comtika = new SysComtikaMerchant();
+				comtika.setMerchantId(ctkRefund.getMerchantId());
+				comtika.setRegisterStatus(2);
+				comtika = sysComtikaMerchantDao.templateOne(comtika);
+				String refundDesc =  "结束充电";
+				// 发起退款
+				RespWrapper<Object> result = refund(ctkRefund.getRefundFee(),refundDesc,cro.getPayTransactionId(),refundFlowId,comtika.getSubMchId());
+				JSONObject json = JSONObject.parseObject(result.getData().toString());
+				if (result.isSuccess()) {
+					ctkRefund.setStatus(MyBankRefundType.ACCEPTANCE.getId());
+					//康体佳服务商平台受理成功返回的单号
+					String refundOrderId = json.getString("refundId");
+					ctkRefund.setRefundOrderNo(refundOrderId);
+					ctkRefund.setRefundMsg("康体佳服务商平台受理成功");
+					refundDao.updateTemplateById(ctkRefund);
+				} else {
+					ctkRefund.setStatus(MyBankRefundType.FAIRLY.getId());// 康体佳服务商平台受理失败
+					if (json.get("respMsg") != null) {
+						ctkRefund.setRefundMsg(String.valueOf(json.get("respMsg")));
+					}
+					refundDao.updateTemplateById(ctkRefund);
+				}
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+	}
+
+	@SuppressWarnings("unchecked")
+	@Override
+	public RespWrapper<Object> uploadPhoto(MultipartFile file) {
+		try {
+			String url = host + upload;
+			Map<String, Object> json = new HashMap<String, Object>();
+			//String result = ComtikaHttpsUtil.upload(url,file);
+			String result = ComtikaHttpsUtil.upload(url,file);
+            RespWrapper<Object> data = JSONObject.parseObject(result,RespWrapper.class);
+            return data;
+        } catch (Exception e) {
+            e.printStackTrace();
+            return RespWrapper.makeErrorResp("服务器错误,请重试!");
+        }
+		
+	}
+
+	@Override
+	public RespWrapper<Object> queryMerchant(Long merchantId) {
+		try {
+			if( null == merchantId){}
+			SysComtikaMerchant sys = new SysComtikaMerchant();
+			sys.setMerchantId(merchantId);
+			sys = sysComtikaMerchantDao.templateOne(sys);
+			return RespWrapper.makeSuccessResp(sys);
+		} catch (Exception e) {
+			e.printStackTrace();
+			return RespWrapper.makeErrorResp("服务器错误!");
+		}
+		
+	}
+
+	
+
+}

+ 399 - 0
ctkcloud-mybank-service/src/main/java/com/comtika/ctkcloud/server/util/http/HTTPUtils.java

@@ -0,0 +1,399 @@
+/**
+* File: HTTPUtils.java
+* Description: TODO
+* Copyright (c)  2019大风软件   All right reserved
+* @author: LYP
+* @version: 1.0
+* @Date: 2019-3-16
+*/
+package com.comtika.ctkcloud.server.util.http;
+
+/**
+ * @ClassName: HTTPUtils 
+ * @Description: TODO
+ * @author: LYP
+ * @version: 1.0
+ */
+import java.io.BufferedReader;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.security.InvalidKeyException;
+import java.security.NoSuchAlgorithmException;
+import java.security.SignatureException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.net.ssl.HostnameVerifier;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSession;
+
+/**
+ * Http请求
+ * @author mszhou
+ *
+ */
+public class HTTPUtils {
+    private static final int TIMEOUT = 45000;
+    public static final String ENCODING = "UTF-8";
+    
+    
+    /**
+	 * 
+	 * 发起Http的get请求
+	 * 
+	 * @param property
+	 *            请求头参数
+	 * 
+	 * @url 请求的地址
+	 * 
+	 * @return 响应内容[Map<String, List<String>>(响应头),String(响应体)]
+	 * @throws SignatureException 
+	 * @throws NoSuchAlgorithmException 
+	 * @throws UnsupportedEncodingException 
+	 * @throws InvalidKeyException 
+	 */
+	@SuppressWarnings("unused")
+	public static String weChatGet(String url,Map<String, String> property) {
+		StringBuffer buffer = null;
+		Map<String, List<String>> headerFields = null;
+		try {
+			URL u = new URL(url);
+			HttpsURLConnection conn = (HttpsURLConnection) u.openConnection();
+			Set<String> keySet = property.keySet();
+			for (String key : keySet) {
+				conn.setRequestProperty(key, property.get(key));
+			}
+			// 设置当前实例使用的SSLSoctetFactory
+			conn.connect();
+			// 读取服务器返回的响应头
+			headerFields = conn.getHeaderFields();
+			// 读取服务器端返回的内容
+			InputStream is = conn.getInputStream();
+			InputStreamReader isr = new InputStreamReader(is, "utf-8");
+			BufferedReader br = new BufferedReader(isr);
+			buffer = new StringBuffer();
+			String line = null;
+			while ((line = br.readLine()) != null) {
+				buffer.append(line);
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+		return String.valueOf(buffer);
+	}
+    
+    /**
+     * 创建HTTP连接
+     * 
+     * @param url
+     *            地址
+     * @param method
+     *            方法
+     * @param headerParameters
+     *            头信息
+     * @param body
+     *            请求内容
+     * @return
+     * @throws Exception
+     */
+    private static HttpURLConnection createConnection(String url,
+            String method, Map<String, String> headerParameters, String body)
+            throws Exception {
+        URL Url = new URL(url);
+        trustAllHttpsCertificates();
+        HttpURLConnection httpConnection = (HttpURLConnection) Url
+                .openConnection();
+        // 设置请求时间
+        httpConnection.setConnectTimeout(TIMEOUT);
+        // 设置 header
+        if (headerParameters != null) {
+            Iterator<String> iteratorHeader = headerParameters.keySet()
+                    .iterator();
+            while (iteratorHeader.hasNext()) {
+            	
+                String key = iteratorHeader.next();
+                httpConnection.setRequestProperty(key,
+                        headerParameters.get(key));
+                System.out.println(key + ":" + headerParameters.get(key));
+            }
+        }
+        
+
+        // 设置请求方法
+        httpConnection.setRequestMethod(method);
+        httpConnection.setDoOutput(true);
+        httpConnection.setDoInput(true);
+        // 写query数据流
+        if (!(body == null || body.trim().equals(""))) {
+            OutputStream writer = httpConnection.getOutputStream();
+            try {
+                writer.write(body.getBytes(ENCODING));
+            } finally {
+                if (writer != null) {
+                    writer.flush();
+                    writer.close();
+                }
+            }
+        }
+
+        // 请求结果
+        int responseCode = httpConnection.getResponseCode();
+        if (responseCode != 200) {
+            throw new Exception(responseCode
+                    + ":"
+                    + inputStream2String(httpConnection.getErrorStream(),
+                            ENCODING));
+        }
+
+        return httpConnection;
+    }
+
+    /**
+     * POST请求
+     * @param address 请求地址
+     * @param headerParameters 参数
+     * @param body
+     * @return
+     * @throws Exception
+     */
+    public static String post(String address,
+            Map<String, String> headerParameters, String body) throws Exception {
+
+       /* return proxyHttpRequest(address, "POST", null,
+                getRequestBody(headerParameters));*/
+        return proxyHttpRequest(address, "POST", headerParameters,
+                getRequestBody(body));
+    }
+
+    
+
+    
+
+    
+
+    /**
+     * 读取文件流
+     * @param in
+     * @return
+     * @throws Exception
+     */
+    public static String readInputStream(InputStream in, File file)
+            throws Exception {
+        FileOutputStream out = null;
+        ByteArrayOutputStream output = null;
+
+        try {
+            output = new ByteArrayOutputStream();
+            byte[] buffer = new byte[1024];
+            int len = 0;
+            while ((len = in.read(buffer)) != -1) {
+                output.write(buffer, 0, len);
+            }
+
+            out = new FileOutputStream(file);
+            out.write(output.toByteArray());
+
+        } catch (Exception e) {
+            throw e;
+        } finally {
+            if (output != null) {
+                output.close();
+            }
+            if (out != null) {
+                out.close();
+            }
+        }
+        return "success";
+    }
+
+    public static byte[] readInputStreamToByte(InputStream in) throws Exception {
+        FileOutputStream out = null;
+        ByteArrayOutputStream output = null;
+        byte[] byteFile = null;
+
+        try {
+            output = new ByteArrayOutputStream();
+            byte[] buffer = new byte[1024];
+            int len = 0;
+            while ((len = in.read(buffer)) != -1) {
+                output.write(buffer, 0, len);
+            }
+            byteFile = output.toByteArray();
+        } catch (Exception e) {
+            throw e;
+        } finally {
+            if (output != null) {
+                output.close();
+            }
+            if (out != null) {
+                out.close();
+            }
+        }
+
+        return byteFile;
+    }
+
+    /**
+     * HTTP请求
+     * 
+     * @param address
+     *            地址
+     * @param method
+     *            方法
+     * @param headerParameters
+     *            头信息
+     * @param body
+     *            请求内容
+     * @return
+     * @throws Exception
+     */
+    public static String proxyHttpRequest(String address, String method,
+            Map<String, String> headerParameters, String body) throws Exception {
+        String result = null;
+        HttpURLConnection httpConnection = null;
+
+        try {
+            httpConnection = createConnection(address, method,
+                    headerParameters, body);
+
+            String encoding = "UTF-8";
+            if (httpConnection.getContentType() != null
+                    && httpConnection.getContentType().indexOf("charset=") >= 0) {
+                encoding = httpConnection.getContentType()
+                        .substring(
+                                httpConnection.getContentType().indexOf(
+                                        "charset=") + 8);
+            }
+            result = inputStream2String(httpConnection.getInputStream(),
+                    encoding);
+            // logger.info("HTTPproxy response: {},{}", address,
+            // result.toString());
+
+        } catch (Exception e) {
+            // logger.info("HTTPproxy error: {}", e.getMessage());
+            throw e;
+        } finally {
+            if (httpConnection != null) {
+                httpConnection.disconnect();
+            }
+        }
+        return result;
+    }
+
+    /**
+     * 将参数化为 body
+     * @param params
+     * @return
+     */
+    public static String getRequestBody(String params) {
+        return getRequestBody(params, true);
+    }
+
+    /**
+     * 将参数化为 body
+     * @param params
+     * @return
+     */
+    public static String getRequestBody(String params,
+            boolean urlEncode) {
+        StringBuilder body = new StringBuilder();
+        try {
+        	body.append(params);
+        	//body.append(URLEncoder.encode(params, ENCODING));
+		} catch (Exception e) {
+			e.printStackTrace();
+		}
+        if (body.length() == 0) {
+            return "";
+        }
+        return body.toString();
+    }
+
+    /**
+     * 读取inputStream 到 string
+     * @param input
+     * @param encoding
+     * @return
+     * @throws IOException
+     */
+    private static String inputStream2String(InputStream input, String encoding)
+            throws IOException {
+        BufferedReader reader = new BufferedReader(new InputStreamReader(input,
+                encoding));
+        StringBuilder result = new StringBuilder();
+        String temp = null;
+        while ((temp = reader.readLine()) != null) {
+            result.append(temp);
+        }
+
+        return result.toString();
+
+    }
+
+
+    /**
+     * 设置 https 请求
+     * @throws Exception
+     */
+    private static void trustAllHttpsCertificates() throws Exception {
+        HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
+            public boolean verify(String str, SSLSession session) {
+                return true;
+            }
+        });
+        javax.net.ssl.TrustManager[] trustAllCerts = new javax.net.ssl.TrustManager[1];
+        javax.net.ssl.TrustManager tm = new miTM();
+        trustAllCerts[0] = tm;
+        javax.net.ssl.SSLContext sc = javax.net.ssl.SSLContext
+                .getInstance("SSL");
+        sc.init(null, trustAllCerts, null);
+        javax.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(sc
+                .getSocketFactory());
+    }
+
+
+    //设置 https 请求证书
+    static class miTM implements javax.net.ssl.TrustManager,javax.net.ssl.X509TrustManager {
+
+        public java.security.cert.X509Certificate[] getAcceptedIssuers() {
+            return null;
+        }
+
+        public boolean isServerTrusted(
+                java.security.cert.X509Certificate[] certs) {
+            return true;
+        }
+
+        public boolean isClientTrusted(
+                java.security.cert.X509Certificate[] certs) {
+            return true;
+        }
+
+        public void checkServerTrusted(
+                java.security.cert.X509Certificate[] certs, String authType)
+                throws java.security.cert.CertificateException {
+            return;
+        }
+
+        public void checkClientTrusted(
+                java.security.cert.X509Certificate[] certs, String authType)
+                throws java.security.cert.CertificateException {
+            return;
+        }
+
+
+    }
+
+
+}
+

+ 101 - 0
ctkcloud-mybank-service/src/main/java/com/comtika/ctkcloud/server/web/ComtikaController.java

@@ -0,0 +1,101 @@
+package com.comtika.ctkcloud.server.web;
+
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiOperation;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.PostMapping;
+import org.springframework.web.bind.annotation.RequestBody;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.multipart.MultipartFile;
+
+import com.comtika.ctkcloud.common.base.action.BaseController;
+import com.comtika.ctkcloud.common.result.RespWrapper;
+import com.comtika.ctkcloud.server.entity.MybankPay;
+import com.comtika.ctkcloud.server.entity.comtikawechat.ComtikaRegisterMerchant;
+import com.comtika.ctkcloud.server.service.comtika.ComtikaMerchantService;
+
+@Api(value = "")
+@RestController
+@RequestMapping("/comtika")
+public class ComtikaController extends BaseController{
+	
+	@Autowired
+	private ComtikaMerchantService comtikaMerchantService;
+	
+	
+	/**
+	 * 商户进件
+	 * @param registerMerchant
+	 * @return
+	 */
+	@PostMapping("/weChatRegisterMerchant")
+	public RespWrapper<Object> weChatRegisterMerchant(@RequestBody ComtikaRegisterMerchant comtikaRegisterMerchant){
+		//System.out.println(registerMerchant.toString());
+		return comtikaMerchantService.weChatRegisterMerchant(comtikaRegisterMerchant);
+	}
+	
+	/**
+	 * 商户进件结果查询
+	 * @param registerMerchant
+	 * @return
+	 */
+	@PostMapping("/queryWeChatRegisterMerchant")
+	public RespWrapper<Object> queryWeChatRegisterMerchant(String businessCode){
+		//System.out.println(registerMerchant.toString());
+		return comtikaMerchantService.queryWeChatRegisterMerchant(businessCode);
+	}
+	
+	
+	/**
+	 * 微信支付下单
+	 * @param registerMerchant
+	 * @return
+	 */
+	@PostMapping("/jsapiUnifiedOrder")
+	public RespWrapper<Object> jsapiUnifiedOrder(@RequestBody MybankPay mybankPay){
+		if(mybankPay == null) return RespWrapper.makeFailResp("入参不能为空");
+        if(mybankPay.getTotalFee() < 0 )return RespWrapper.makeFailResp("支付金额不能小于最小值");
+        if(mybankPay.getStreamNo() == null)return RespWrapper.makeFailResp("插座编号不能为空!");
+        Long userId = super.getCurrentIdByHead();
+        if(userId == null)return RespWrapper.makeUnLoginResp("token无效,您可以尝试重新登录后再试!");
+        String ip = super.getIpAddrForwardedIp();
+		return comtikaMerchantService.jsapiUnifiedOrder(mybankPay,ip,userId);
+	}
+	
+	
+	@PostMapping("/notify")
+    public void notify(HttpServletResponse response,HttpServletRequest request){
+		comtikaMerchantService.notify(response,request);
+    }
+	
+	
+	@ApiOperation(value = "这个是钱包充值", notes = "这个是钱包充值")
+    @ApiImplicitParam(name = "mybankPay", value = "支付参数", required = false, dataType = "MybankPay")
+    @PostMapping("/comtikaPrePay")
+    public RespWrapper<Object> daFengPrePay(@RequestBody MybankPay mybankPay){
+        Long userId = super.getCurrentIdByHead();
+        String ip = super.getIpAddrForwardedIp();
+        if(userId == null)return RespWrapper.makeUnLoginResp("token无效,您可以尝试重新登录后再试!");
+        return comtikaMerchantService.comtikaPrePay(mybankPay,userId,ip);
+    }
+	
+	
+	/*@ApiOperation(value = "这个是图片上传", notes = "这个是图片上传")
+	@PostMapping("/uploadPhoto")
+    public RespWrapper<Object> uploadPhoto(MultipartFile file) {
+		return comtikaMerchantService.uploadPhoto(file);
+	}*/
+	
+	@ApiOperation(value = "云平台查询商户入驻信息", notes = "云平台查询商户入驻信息")
+	@PostMapping("/queryMerchant")
+    public RespWrapper<Object> queryMerchant(Long merchantId) {
+		return comtikaMerchantService.queryMerchant(merchantId);
+	}
+}

+ 18 - 0
ctkcloud-mybank-service/src/main/resources/sql/comtika/merchant.md

@@ -0,0 +1,18 @@
+queryComtikaMerchant
+===
+SELECT 
+	cs.site_id,
+	cs.merchant_id ,
+	scm.register_status,
+	scm.sub_mchId 
+FROM 
+(SELECT 
+    merchant_id,id AS site_id 
+  FROM
+    ctk_site 
+  WHERE id = (SELECT site_id FROM ctk_equip_terminal WHERE id = (SELECT equip_terminal_id FROM ctk_equip_node WHERE id = (SELECT equip_node_id FROM ctk_equip_socket WHERE 1 = 2 
+@if(!isEmpty(streamNo)){
+	OR serial_no = #streamNo#
+@}
+  ))))cs
+  LEFT JOIN sys_comtika_merchant scm ON  cs.merchant_id = scm.merchant_id