@@ -114,7 +114,7 @@ public interface TtOpenMaService extends TtMaService { | |||||
/** | /** | ||||
* 2. 获取体验小程序的体验二维码 | * 2. 获取体验小程序的体验二维码 | ||||
*/ | */ | ||||
String API_TEST_QRCODE = "https://api.weixin.qq.com/wxa/get_qrcode"; | |||||
String API_TEST_QRCODE = "https://open.microapp.bytedance.com/openapi/v1/microapp/app/qrcode"; | |||||
/** | /** | ||||
* 3. 获取授权小程序帐号的可选类目 | * 3. 获取授权小程序帐号的可选类目 | ||||
@@ -0,0 +1,34 @@ | |||||
package com.iformall.service.toutiao.api.bean; | |||||
import cn.binarywang.wx.miniapp.bean.AbstractWxMaQrcodeWrapper; | |||||
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; | |||||
import lombok.Data; | |||||
import lombok.EqualsAndHashCode; | |||||
import java.io.Serializable; | |||||
/** | |||||
* @author <a href="https://github.com/binarywang">Binary Wang</a> | |||||
*/ | |||||
@Data | |||||
@EqualsAndHashCode(callSuper = false) | |||||
public class TtOpenMaQrcode extends AbstractWxMaQrcodeWrapper implements Serializable { | |||||
private String version; | |||||
private String path; | |||||
public TtOpenMaQrcode(String version, String path) { | |||||
this.version = version; | |||||
this.path = path; | |||||
} | |||||
public static TtOpenMaQrcode fromJson(String json) { | |||||
return WxMaGsonBuilder.create().fromJson(json, TtOpenMaQrcode.class); | |||||
} | |||||
@Override | |||||
public String toString() { | |||||
return WxMaGsonBuilder.create().toJson(this); | |||||
} | |||||
} |
@@ -8,7 +8,10 @@ import com.google.gson.JsonObject; | |||||
import com.iformall.service.toutiao.api.TtOpenComponentService; | import com.iformall.service.toutiao.api.TtOpenComponentService; | ||||
import com.iformall.service.toutiao.api.TtOpenMaService; | import com.iformall.service.toutiao.api.TtOpenMaService; | ||||
import com.iformall.service.toutiao.api.bean.TtOpenGsonBuilder; | import com.iformall.service.toutiao.api.bean.TtOpenGsonBuilder; | ||||
import com.iformall.service.toutiao.api.bean.TtOpenMaQrcode; | |||||
import com.iformall.service.toutiao.api.bean.TtOpenResult; | import com.iformall.service.toutiao.api.bean.TtOpenResult; | ||||
import com.iformall.service.toutiao.miniapp.TtMaQrcode; | |||||
import com.iformall.service.toutiao.miniapp.TtQrcodeRequestExecutor; | |||||
import com.iformall.service.toutiao.miniapp.impl.TtMaServiceImpl; | import com.iformall.service.toutiao.miniapp.impl.TtMaServiceImpl; | ||||
import lombok.extern.java.Log; | import lombok.extern.java.Log; | ||||
import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||
@@ -316,9 +319,10 @@ public class TtOpenMaServiceImpl extends TtMaServiceImpl implements TtOpenMaServ | |||||
*/ | */ | ||||
@Override | @Override | ||||
public File getTestQrcode(String pagePath, Map<String, String> params) throws WxErrorException { | public File getTestQrcode(String pagePath, Map<String, String> params) throws WxErrorException { | ||||
WxMaQrcodeParam qrcodeParam = WxMaQrcodeParam.create(pagePath); | |||||
qrcodeParam.addPageParam(params); | |||||
return execute(MaQrCodeRequestExecutor.create(getRequestHttp()), API_TEST_QRCODE, qrcodeParam); | |||||
String uri = API_TEST_QRCODE +"?component_appid="+ttOpenComponentService.getWxOpenConfigStorage().getComponentAppId() | |||||
+"&authorizer_access_token="+getAccessToken(false); | |||||
final TtQrcodeRequestExecutor executor = new TtQrcodeRequestExecutor(this.getRequestHttp()); | |||||
return this.execute(executor, uri, new TtOpenMaQrcode("audit",pagePath)); | |||||
} | } | ||||
/** | /** | ||||
@@ -46,6 +46,14 @@ import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.stereotype.Controller; | import org.springframework.stereotype.Controller; | ||||
import org.springframework.web.bind.annotation.*; | import org.springframework.web.bind.annotation.*; | ||||
import javax.servlet.ServletOutputStream; | |||||
import javax.servlet.http.HttpServletRequest; | |||||
import javax.servlet.http.HttpServletResponse; | |||||
import java.io.File; | |||||
import java.io.FileInputStream; | |||||
import java.io.IOException; | |||||
import java.io.InputStream; | |||||
import java.net.URLEncoder; | |||||
import java.util.*; | import java.util.*; | ||||
/** | /** | ||||
@@ -1048,4 +1056,43 @@ public class WxWeappInfoController extends BaseController { | |||||
* 22. oauth2refreshAccessToken | * 22. oauth2refreshAccessToken | ||||
*/ | */ | ||||
@ApiOperation("获取体验小程序的体验二维码") | |||||
@GetMapping("/getQrcode") | |||||
public void getQrcode(@RequestParam(value = "appId") String appId, @RequestParam(value = "pagePath") String pagePath, | |||||
@RequestParam(value = "params", required = false) Map<String, String> params, | |||||
HttpServletResponse response, HttpServletRequest req) { | |||||
try { | |||||
TtOpenMaService openMaService = openService.getTtOpenComponentService().getTtMaServiceByAppid(appId); | |||||
File file = openMaService.getTestQrcode(pagePath,params); | |||||
ServletOutputStream out = response.getOutputStream(); | |||||
response.reset(); | |||||
response.setContentType("image/jpeg"); | |||||
String agent = req.getHeader("user-agent"); | |||||
String filename = "QRCode.jpg"; | |||||
if (agent.contains("Firefox")) { | |||||
response.setHeader("Content-disposition", | |||||
"attachment; filename=" + new String(filename.getBytes("GB2312"),"ISO-8859-1")); | |||||
} else { | |||||
response.setHeader("Content-disposition", | |||||
"attachment; filename=" + URLEncoder.encode(filename,"UTF-8")); | |||||
} | |||||
// 循环取出流中的数据 | |||||
byte[] b = new byte[1024]; | |||||
int len; | |||||
InputStream inStream = new FileInputStream(file); | |||||
while ((len = inStream.read(b)) > 0) | |||||
response.getOutputStream().write(b, 0, len); | |||||
inStream.close(); | |||||
} catch (WxErrorException e) { | |||||
logger.error(e.getMessage()); | |||||
} catch (IOException e) { | |||||
logger.error(e.getMessage()); | |||||
} | |||||
} | |||||
} | } |