| | |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.stylefeng.guns.core.common.exception.BizExceptionEnum; |
| | | import com.stylefeng.guns.core.exception.GunsException; |
| | | import com.stylefeng.guns.core.util.ToolUtil; |
| | | import com.stylefeng.guns.modular.account.service.ITEnterpriseWithdrawalService; |
| | | import com.stylefeng.guns.modular.account.service.UserWithdrawalService; |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.ByteArrayInputStream; |
| | | import java.io.File; |
| | | import java.io.InputStream; |
| | | import java.io.PrintWriter; |
| | | import java.math.BigDecimal; |
| | | import java.security.SecureRandom; |
| | | import java.util.Map; |
| | | import java.util.UUID; |
| | | |
| | |
| | | |
| | | // 3. 构建scene参数(最大32字符) |
| | | StringBuilder sceneBuilder = new StringBuilder(); |
| | | sceneBuilder.append("id=").append(lineShiftDriverId); |
| | | sceneBuilder.append("driverId=").append(driverId); |
| | | if (ToolUtil.isNotEmpty(otherFee)) { |
| | | sceneBuilder.append("&f=").append(otherFee); |
| | | } |
| | | String scene = sceneBuilder.toString(); |
| | | if (scene.length() > 32) { |
| | | return ResultUtil.error("生成小程序码失败:scene参数超长"); |
| | | } |
| | | |
| | | // 4. 生成小程序码 |
| | | String page = "pages/scanOrder/scanOrder"; // 小程序跳转页面 |
| | | String envVersion = env.equals("prod") ? "release" : "trial"; // 正式版环境 |
| | | InputStream inputStream = weChatUtil.getwxacodeunlimit(page, scene, envVersion); |
| | | |
| | | if (null == inputStream) { |
| | | return ResultUtil.error("生成小程序码失败"); |
| | | } |
| | | |
| | | // 5. 上传到服务器 |
| | | File file = FileUtil.writeFromStream(inputStream, new File(filePath + "/" + UUID.randomUUID().toString() + ".png")); |
| | | HttpRequest post = HttpUtil.createPost(adminUrl + "/upload/image"); |
| | | post.form("file", file); |
| | | HttpResponse execute = post.execute(); |
| | | int status = execute.getStatus(); |
| | | if (200 != status) { |
| | | throw new RuntimeException("上传图片异常"); |
| | | } |
| | | String page = "pages/index/index"; // 小程序跳转页面 |
| | | String unlimitQrcodeUrl = weChatUtil.getUnlimitQrcode(page, scene); |
| | | // 6. 返回结果 |
| | | BaseWarpper baseWarpper = new BaseWarpper(); |
| | | baseWarpper.setContent(JSONObject.parseObject(execute.body()).get("data").toString()); |
| | | baseWarpper.setContent(unlimitQrcodeUrl); |
| | | return ResultUtil.success(baseWarpper); |
| | | |
| | | } catch (Exception e) { |