|  |  | @ -1,5 +1,6 @@ | 
			
		
	
		
			
				
					|  |  |  | package com.epmet.service.impl; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | import com.alibaba.fastjson.JSON; | 
			
		
	
		
			
				
					|  |  |  | import com.alibaba.fastjson.JSONObject; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.constant.NumConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.exception.RenException; | 
			
		
	
	
		
			
				
					|  |  | @ -16,22 +17,20 @@ import com.epmet.dto.result.*; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.feign.OperCrmOpenFeignClient; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.feign.OssFeignClient; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.service.*; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.wxapi.param.WxMaCodeAuditStatusReq; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.wxapi.param.WxMaCodeCommitReq; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.wxapi.param.WxMaCodeSubmitAuditRequest; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.wxapi.param.WxMaNewsReq; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.wxapi.param.*; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.wxapi.result.*; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.wxapi.service.WxMaCodeService; | 
			
		
	
		
			
				
					|  |  |  | import com.github.pagehelper.PageHelper; | 
			
		
	
		
			
				
					|  |  |  | import com.github.pagehelper.PageInfo; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.mock.web.MockMultipartFile; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.stereotype.Service; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.web.multipart.MultipartFile; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | import java.io.File; | 
			
		
	
		
			
				
					|  |  |  | import java.io.FileOutputStream; | 
			
		
	
		
			
				
					|  |  |  | import java.io.OutputStream; | 
			
		
	
		
			
				
					|  |  |  | import java.nio.file.Files; | 
			
		
	
		
			
				
					|  |  |  | import java.util.ArrayList; | 
			
		
	
		
			
				
					|  |  |  | import java.util.Collections; | 
			
		
	
		
			
				
					|  |  |  | import java.util.List; | 
			
		
	
	
		
			
				
					|  |  | @ -68,8 +67,6 @@ public class CodeServiceImpl implements CodeService { | 
			
		
	
		
			
				
					|  |  |  | 	private OssFeignClient ossFeignClient; | 
			
		
	
		
			
				
					|  |  |  | 	@Autowired | 
			
		
	
		
			
				
					|  |  |  | 	private PaCustomerService paCustomerService; | 
			
		
	
		
			
				
					|  |  |  | 	@Autowired | 
			
		
	
		
			
				
					|  |  |  | 	private WxMaCodeService wxsMaCodeService; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	@Override | 
			
		
	
		
			
				
					|  |  |  | 	public List<TemplateListResultDTO> templateList() { | 
			
		
	
	
		
			
				
					|  |  | @ -104,6 +101,15 @@ public class CodeServiceImpl implements CodeService { | 
			
		
	
		
			
				
					|  |  |  | 		return codeExtDTO.getExtJson(); | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	public static void main(String[] args) { | 
			
		
	
		
			
				
					|  |  |  | 		String json = "{\"extEnable\":true,\"extAppid\":\"wx2679392c4cc2af22\",\"directCommit\":false,\"ext\":{\"extAppid\":\"wx2679392c4cc2af22\",\"footbar\":{\"work\":{\"name\":\"工作\",\"pageTile\":\"工作\"},\"org\":{\"name\":\"组织\",\"pageTile\":\"组织\"},\"data\":{\"name\":\"数据\",\"pageTile\":\"数据\"},\"find\":{\"name\":\"更多\",\"pageTile\":\"更多\"}}}}"; | 
			
		
	
		
			
				
					|  |  |  | 		WxExtJson wxExtJson = JSONObject.parseObject(json, WxExtJson.class); | 
			
		
	
		
			
				
					|  |  |  | 		wxExtJson.setExtAppid("123456"); | 
			
		
	
		
			
				
					|  |  |  | 		wxExtJson.getExt().setExtAppid("123456"); | 
			
		
	
		
			
				
					|  |  |  | 		String extJson = JSON.toJSONString(wxExtJson); | 
			
		
	
		
			
				
					|  |  |  | 		System.out.println(extJson); | 
			
		
	
		
			
				
					|  |  |  | 	} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 	@Override | 
			
		
	
		
			
				
					|  |  |  | 	@Transactional(rollbackFor = Exception.class) | 
			
		
	
		
			
				
					|  |  |  | 	public void upload(CodeUploadFormDTO formDTO) { | 
			
		
	
	
		
			
				
					|  |  | @ -120,20 +126,24 @@ public class CodeServiceImpl implements CodeService { | 
			
		
	
		
			
				
					|  |  |  | 			throw new RenException("第三方配置不是有效的Json"); | 
			
		
	
		
			
				
					|  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		WxExtJson wxExtJson = JSONObject.parseObject(formDTO.getExtJson(), WxExtJson.class); | 
			
		
	
		
			
				
					|  |  |  | 		wxExtJson.setExtAppid(authInfo.getAuthorizerAppid()); | 
			
		
	
		
			
				
					|  |  |  | 		wxExtJson.getExt().setExtAppid(authInfo.getAuthorizerAppid()); | 
			
		
	
		
			
				
					|  |  |  | 		String extJson = JSON.toJSONString(wxExtJson); | 
			
		
	
		
			
				
					|  |  |  | 		CodeExtDTO codeExtDTO = codeExtService.getExtByCustomer(formDTO.getCustomerId(), formDTO.getClientType()); | 
			
		
	
		
			
				
					|  |  |  | 		if (null == codeExtDTO) { | 
			
		
	
		
			
				
					|  |  |  | 			codeExtDTO = new CodeExtDTO(); | 
			
		
	
		
			
				
					|  |  |  | 			codeExtDTO.setCustomerId(formDTO.getCustomerId()); | 
			
		
	
		
			
				
					|  |  |  | 			codeExtDTO.setClientType(formDTO.getClientType()); | 
			
		
	
		
			
				
					|  |  |  | 			codeExtDTO.setAppId(authInfo.getAuthorizerAppid()); | 
			
		
	
		
			
				
					|  |  |  | 			codeExtDTO.setExtJson(formDTO.getExtJson()); | 
			
		
	
		
			
				
					|  |  |  | 			codeExtDTO.setExtJson(extJson); | 
			
		
	
		
			
				
					|  |  |  | 			codeExtService.save(codeExtDTO); | 
			
		
	
		
			
				
					|  |  |  | 		} | 
			
		
	
		
			
				
					|  |  |  | 		codeExtDTO.setExtJson(formDTO.getExtJson()); | 
			
		
	
		
			
				
					|  |  |  | 		codeExtDTO.setExtJson(extJson); | 
			
		
	
		
			
				
					|  |  |  | 		codeExtService.update(codeExtDTO); | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | 		WxMaCodeCommitReq request = ConvertUtils.sourceToTarget(formDTO, WxMaCodeCommitReq.class); | 
			
		
	
		
			
				
					|  |  |  | 		request.setExtJson(formDTO.getExtJson()); | 
			
		
	
		
			
				
					|  |  |  | 		request.setExtJson(extJson); | 
			
		
	
		
			
				
					|  |  |  | 		//调用微信API上传代码
 | 
			
		
	
		
			
				
					|  |  |  | 		WxResult wxResult = wxMaCodeService.commit(authInfo.getAuthorizerAccessToken(), request); | 
			
		
	
		
			
				
					|  |  |  | 		//上传失败,抛出异常
 | 
			
		
	
	
		
			
				
					|  |  | @ -151,7 +161,7 @@ public class CodeServiceImpl implements CodeService { | 
			
		
	
		
			
				
					|  |  |  | 		//将上传信息存入表中
 | 
			
		
	
		
			
				
					|  |  |  | 		CodeCustomerDTO codeCustomerDTO = ConvertUtils.sourceToTarget(formDTO, CodeCustomerDTO.class); | 
			
		
	
		
			
				
					|  |  |  | 		codeCustomerDTO.setCustomerName(paCustomerDTO.getCustomerName()); | 
			
		
	
		
			
				
					|  |  |  | 		codeCustomerDTO.setExtJson(formDTO.getExtJson()); | 
			
		
	
		
			
				
					|  |  |  | 		codeCustomerDTO.setExtJson(extJson); | 
			
		
	
		
			
				
					|  |  |  | 		codeCustomerDTO.setAppId(authInfo.getAuthorizerAppid()); | 
			
		
	
		
			
				
					|  |  |  | 		codeCustomerDTO.setStatus(CodeConstant.UNAUDITED); | 
			
		
	
		
			
				
					|  |  |  | 		codeCustomerService.save(codeCustomerDTO); | 
			
		
	
	
		
			
				
					|  |  | @ -374,9 +384,9 @@ public class CodeServiceImpl implements CodeService { | 
			
		
	
		
			
				
					|  |  |  | 		AuthorizationInfoDTO authInfo = authorizationInfoDao.getAuthInfoByCustomer(codeCustomerDTO.getCustomerId(), codeCustomerDTO.getClientType()); | 
			
		
	
		
			
				
					|  |  |  | 		//调用微信API获取获取体验版二维码
 | 
			
		
	
		
			
				
					|  |  |  | 		WxResult<byte[]> wxResult = wxMaCodeService.getQrCode(authInfo.getAuthorizerAccessToken(), formDTO.getPath()); | 
			
		
	
		
			
				
					|  |  |  | 		QrCodeDTO qrCodeDTO = new QrCodeDTO(); | 
			
		
	
		
			
				
					|  |  |  | 		qrCodeDTO.setQrCode(wxResult.getData()); | 
			
		
	
		
			
				
					|  |  |  | 		Result<UploadImgResultDTO> uploadResult = ossFeignClient.uploadQrCode(qrCodeDTO); | 
			
		
	
		
			
				
					|  |  |  | 		MultipartFile file = null; | 
			
		
	
		
			
				
					|  |  |  | 		file = new MockMultipartFile("file", "QRCode.jpg", "image/jpeg", wxResult.getData()); | 
			
		
	
		
			
				
					|  |  |  | 		Result<UploadImgResultDTO> uploadResult = ossFeignClient.uploadQrCode(file); | 
			
		
	
		
			
				
					|  |  |  | 		codeCustomerDTO.setQrCode(uploadResult.getData().getUrl()); | 
			
		
	
		
			
				
					|  |  |  | 		codeCustomerService.update(codeCustomerDTO); | 
			
		
	
		
			
				
					|  |  |  | 		result.setQrcode(uploadResult.getData().getUrl()); | 
			
		
	
	
		
			
				
					|  |  | @ -399,9 +409,7 @@ public class CodeServiceImpl implements CodeService { | 
			
		
	
		
			
				
					|  |  |  | 	@Override | 
			
		
	
		
			
				
					|  |  |  | 	public String mediaUpload(MediaUploadFormDTO formDTO) { | 
			
		
	
		
			
				
					|  |  |  | 		try { | 
			
		
	
		
			
				
					|  |  |  | 			QrCodeDTO dto = new QrCodeDTO(); | 
			
		
	
		
			
				
					|  |  |  | 			dto.setMedia(formDTO.getMedia()); | 
			
		
	
		
			
				
					|  |  |  | 			Result<UploadImgResultDTO> uploadWxImg = ossFeignClient.uploadWxImg(dto); | 
			
		
	
		
			
				
					|  |  |  | 			Result<UploadImgResultDTO> uploadWxImg = ossFeignClient.uploadWxImg(formDTO.getMedia()); | 
			
		
	
		
			
				
					|  |  |  | 			File file = new File(uploadWxImg.getData().getUrl()); | 
			
		
	
		
			
				
					|  |  |  | 			//获取上传代码信息
 | 
			
		
	
		
			
				
					|  |  |  | 			CodeCustomerDTO codeCustomerDTO = codeCustomerService.get(formDTO.getCodeId()); | 
			
		
	
	
		
			
				
					|  |  | 
 |