Forráskód Böngészése

获取分享素材小程序码

wjj 3 napja
szülő
commit
01733f899e

+ 19 - 0
fs-company/src/main/java/com/fs/company/controller/qw/FsCompanyCustomerController.java

@@ -493,6 +493,25 @@ public class FsCompanyCustomerController extends BaseController {
         return fsCompanyCustomerService.createPhoneQRCode(qrCodeDTO,companyUserId, appId);
     }
 
+    /**
+     * 获取分享素材小程序码
+     * @param shareMaterialId 分享素材ID
+     */
+    @GetMapping("/getShareMaterialWxCode/{shareMaterialId}")
+    public R getShareMaterialWxCode(@PathVariable("shareMaterialId") Long shareMaterialId) {
+        // 登录用户ID
+        Long companyUserId;
+        try {
+            companyUserId = SecurityUtils.getLoginUser().getUser().getUserId();
+        } catch (Exception e) {
+            log.error("获取当前登录用户信息失败", e);
+            throw new CustomException("登录信息已过期,请重新登录");
+        }
+        // 当前配置的商城小程序appId
+        String appId = getAppId();
+        return fsCompanyCustomerService.getShareMaterialWxCode(companyUserId, appId, null);
+    }
+
     /**
      * 获取 appId 的私有方法
      */

+ 2 - 0
fs-service/src/main/java/com/fs/qw/service/IFsCompanyCustomerService.java

@@ -68,4 +68,6 @@ public interface IFsCompanyCustomerService {
      * @return 创建结果
      */
     R createPhoneQRCode(CreatePhoneQRCodeDTO qrCodeDTO,Long companyUserId, String appId);
+
+    R getShareMaterialWxCode(Long companyUserId, String appId, Long shareMaterialId);
 }

+ 36 - 0
fs-service/src/main/java/com/fs/qw/service/impl/FsCompanyCustomerServiceImpl.java

@@ -499,4 +499,40 @@ public class FsCompanyCustomerServiceImpl implements IFsCompanyCustomerService {
             return R.error("微信接口调用失败: " + e.getMessage());
         }
     }
+
+    @Override
+    public R getShareMaterialWxCode(Long companyUserId, String appId, Long shareMaterialId) {
+        final WxMaService wxMaService = WxMaConfiguration.getMaService(appId);
+        String scene="cuId="+ companyUserId+ "&shareMaterialId=" + shareMaterialId;
+        byte[] file;
+        try {
+            file = wxMaService.getQrcodeService().createWxaCodeUnlimitBytes(
+                    scene,
+                    "/pages_course/customerStatistics",
+                    true,
+                    "release",
+                    430,
+                    true,
+                    null,
+                    false);
+            // ======= 处理图片,替换中间的文字(/n:实现文字换行效果) =======
+            file = QRCodeImageCleaner.replaceCenterText(file, "益寿缘\n大药房");
+            // ==========================================
+            // 上传图片到存储桶
+            String suffix = ".png";
+            CloudStorageService storage = OSSFactory.build();
+            String url;
+            try {
+                url = storage.uploadSuffix(file, suffix);
+            }  catch (Exception e) {
+                log.error("生成图片失败:{}",e.getMessage(),e);
+                return R.error("生成图片失败");
+            }
+            // 返回成功信息
+            return R.ok().put("url",url);
+        } catch (WxErrorException e) {
+            log.error(e.getMessage(), e);
+            return R.error("微信接口调用失败: " + e.getMessage());
+        }
+    }
 }