景区二维码下载
This commit is contained in:
parent
344118e926
commit
d10d706597
@ -6,12 +6,18 @@ import com.ycwl.basic.model.pc.scenic.req.ScenicAddOrUpdateReq;
|
||||
import com.ycwl.basic.model.pc.scenic.req.ScenicReqQuery;
|
||||
import com.ycwl.basic.model.pc.scenic.resp.ScenicRespVO;
|
||||
import com.ycwl.basic.service.pc.ScenicService;
|
||||
import com.ycwl.basic.storage.StorageFactory;
|
||||
import com.ycwl.basic.storage.adapters.IStorageAdapter;
|
||||
import com.ycwl.basic.utils.ApiResponse;
|
||||
import com.ycwl.basic.utils.WxMpUtil;
|
||||
import com.ycwl.basic.repository.ScenicRepository;
|
||||
import com.ycwl.basic.model.pc.mp.MpConfigEntity;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -26,6 +32,9 @@ public class ScenicController {
|
||||
@Autowired
|
||||
private ScenicService scenicService;
|
||||
|
||||
@Autowired
|
||||
private ScenicRepository scenicRepository;
|
||||
|
||||
@ApiOperation("分页查询景区")
|
||||
@PostMapping("/page")
|
||||
public ApiResponse<PageInfo<ScenicRespVO>> pageQuery(@RequestBody ScenicReqQuery scenicReqQuery) {
|
||||
@ -87,4 +96,28 @@ public class ScenicController {
|
||||
scenicService.addConfig(config);
|
||||
return ApiResponse.success(null);
|
||||
}
|
||||
|
||||
@ApiOperation("根据景区ID下载小程序二维码")
|
||||
@GetMapping("/{id}/QRCode")
|
||||
public ApiResponse<String> downloadQrCode(@PathVariable Long id) {
|
||||
MpConfigEntity mpConfig = scenicRepository.getScenicMpConfig(id);
|
||||
if (mpConfig == null) {
|
||||
return ApiResponse.fail("小程序配置不存在");
|
||||
}
|
||||
String appId = mpConfig.getAppId();
|
||||
String appSecret = mpConfig.getAppSecret();
|
||||
String appState = mpConfig.getState();
|
||||
String path = "pages/home/index?scenicId=" + id;
|
||||
String filePath = "qr_code_" + id + ".jpg";
|
||||
try {
|
||||
WxMpUtil.generateWXAQRCode(appId, appSecret, appState, path, filePath);
|
||||
IStorageAdapter adapter = StorageFactory.use();
|
||||
File file = new File(filePath);
|
||||
String s = adapter.uploadFile(file, filePath);
|
||||
file.delete();
|
||||
return ApiResponse.success(s);
|
||||
} catch (Exception e) {
|
||||
return ApiResponse.fail("生成二维码失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,12 +34,12 @@ public class WxMpUtil {
|
||||
return ACCESS_TOKEN;
|
||||
}
|
||||
|
||||
public static void generateWXAQRCode(String appId, String appSecret, String path, String filePath) throws Exception {
|
||||
public static void generateWXAQRCode(String appId, String appSecret, String envVersion, String path, String filePath) throws Exception {
|
||||
String url = String.format(GET_WXA_CODE_URL, getAccessToken(appId, appSecret));
|
||||
CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
HttpPost httpPost = new HttpPost(url);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("env_version", "trial");
|
||||
json.put("env_version", envVersion);
|
||||
json.put("path", path);
|
||||
json.put("width", 1000);
|
||||
StringEntity entity = new StringEntity(json.toJSONString(), "utf-8");
|
||||
@ -58,6 +58,6 @@ public class WxMpUtil {
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
generateWXAQRCode("wxe7ff26af70bfc37c", "5252fbbc68513bc77b7cc0052b9f9695", "pages/home/index?scenicId=3946669713328836608", "cxzh_t.jpg");
|
||||
// generateWXAQRCode("wxe7ff26af70bfc37c", "5252fbbc68513bc77b7cc0052b9f9695", "pages/home/index?scenicId=3946669713328836608", "cxzh_t.jpg");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user