小程序
小游戏
企业微信
微信支付
扫描小程序码分享
media md5 not match, hint: [1589186279_51_26e4b408a53bf40d91d5ccd88d1c6d18], from ip: 223.68.196.14, more info at https://open.work.weixin.qq.com/devtool/query?e=301019
12 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
您好,这个是代码问题,可以参考下{
"msgtype": "image",
"image": {
"base64": "iVBORw0KGgoAAAANSUhEUgAAAIoAAACKCAYAAAB1h9JkAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAF1SURBVHhe7dYxAYAwEMDASgFR4LTYeyQ0Am44BxmyrmcPnAiFZN3vN3AiFBKhkAiFxMySCIVEKCRCITGzJEIhEQqJUEjMLIlQSIRCIhQSM0siFBKhkAiFxMySCIVEKCRCITGzJEIhEQqJUEjMLIlQSIRCIhQSM0siFBKhkAiFxMySCIVEKCRCITGzJEIhEQqJUEjMLIlQSIRCIhQSM0siFBKhkAiFxMySCIVEKCRCITGzJEIhEQqJUEjMLIlQSIRCIhQSM0siFBKhkAiFxMySCIVEKCRCITGzJEIhEQqJUEjMLIlQSIRCIhQSM0siFBKhkAiFxMySCIVEKCRCITGzJEIhEQqJUEjMLIlQSIRCIhQSM0siFBKhkAiFxMySCIVEKCRCITGzJEIhEQqJUEjMLIlQSIRCIhQSM0siFBKhkAiFxMySCIVEKCRCITGzJEIhEQqJUEjMLIlQSIRCIhQSM0siFBKhkAiFxMySCIVEKCRCIdjzA5oVKWxK2iiRAAAAAElFTkSuQmCC",
"md5": "1bf0d144aa88eee8e49462fd2b644b06"
}
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
纯欠骂
/**PHP * 实际测试中发现部分格式企微识别有误 也可能是图片本身问题 没详尽研究 * 未通过 PNG image data, 1500 x 800, 8-bit gray+alpha, non-interlaced * 通过 JPEG image data, JFIF standard 1.01 */ $image = 'xx.jpeg'; $base64 = base64EncodeImage($image); $md5 = md5_file($image); function base64EncodeImage($image_file) { $image_data = fread(fopen($image_file, 'rb'), filesize($image_file)); return base64_encode($image_data); }
md5 和base64 生成及请求
imgkit.from_string(mail_content, 'downloads/111.png' , options={"encoding": "UTF-8"})
f = open('downloads/111.png', 'br')
fcont = f.read()
m2 = hashlib.md5(fcont)
md5_val = m2.hexdigest()
base64_data=str(base64.b64encode(fcont),encoding='utf-8')
r=requests.post(url,data={"msgtype":"image","image":{"base64":base64_data,"md5":md5_val}})
把base64图片内容里的换行符清空了replaceAll("\r|\n", "")
检查下base64中 \r\n的。会影响校验
// 这是java代码可以直接用的参考
import org.apache.commons.codec.digest.DigestUtils;// 重要依赖
@Test
public void Test2() throws Exception {
String purl = "图片url地址";
URL url = new URL(purl);
// 打开连接
URLConnection connection = url.openConnection();
try (
// 获取输入流
InputStream inputStream = connection.getInputStream();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
){
StreamUtils.copy(inputStream, outputStream);
// 发送post请求
String rurl = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=机器人key";
// 设置请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
// 创建请求体
Map<String, Object> image = new HashMap<>();
//关键步骤
image.put("base64", Base64.getEncoder().encodeToString(outputStream.toByteArray()).replaceAll("[\r\n]", ""));
image.put("md5", DigestUtils.md5Hex(outputStream.toByteArray()));
Map<String, Object> requestBody = new HashMap<>();
requestBody.put("msgtype", "image");
requestBody.put("image", image);
// 创建 HttpEntity 对象,包含请求头和请求体
HttpEntity<Map<String, Object>> entity = new HttpEntity<>(requestBody, headers);
// 发送 POST 请求
ResponseEntity<String> response = restTemplate.postForEntity(rurl, entity, String.class);
// 打印响应信息
System.out.println("Response Status Code: " + response.getStatusCode());
System.out.println("Response Body: " + response.getBody());
} catch (RestClientException e) {
throw new RuntimeException(e);
import org.apache.commons.codec.digest.DigestUtils; byte[] bytes = FileUtils.readFileToByteArray(new File("D:\\fsdownload\\bb.jpg")); String md5 = DigestUtils.md5Hex(bytes); //java 的方式
java 版代码,【坑点】转base64后要把\r\n替换掉,实测有效
URL url = new URL(sendMessageContent.getImage()); byte[] imageBytes = IoUtil.readBytes(url.openStream()); String imageBase64Str = Base64.getEncoder().encodeToString(imageBytes) .replaceAll("[\r\n]", ""); String md5 = MD5.create().digestHex(imageBytes);
markdown都不支持图片链接,什么时候支持啊,太👎了
正在加载...
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
您好,这个是代码问题,可以参考下{
"msgtype": "image",
"image": {
"base64": "iVBORw0KGgoAAAANSUhEUgAAAIoAAACKCAYAAAB1h9JkAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAF1SURBVHhe7dYxAYAwEMDASgFR4LTYeyQ0Am44BxmyrmcPnAiFZN3vN3AiFBKhkAiFxMySCIVEKCRCITGzJEIhEQqJUEjMLIlQSIRCIhQSM0siFBKhkAiFxMySCIVEKCRCITGzJEIhEQqJUEjMLIlQSIRCIhQSM0siFBKhkAiFxMySCIVEKCRCITGzJEIhEQqJUEjMLIlQSIRCIhQSM0siFBKhkAiFxMySCIVEKCRCITGzJEIhEQqJUEjMLIlQSIRCIhQSM0siFBKhkAiFxMySCIVEKCRCITGzJEIhEQqJUEjMLIlQSIRCIhQSM0siFBKhkAiFxMySCIVEKCRCITGzJEIhEQqJUEjMLIlQSIRCIhQSM0siFBKhkAiFxMySCIVEKCRCITGzJEIhEQqJUEjMLIlQSIRCIhQSM0siFBKhkAiFxMySCIVEKCRCITGzJEIhEQqJUEjMLIlQSIRCIhQSM0siFBKhkAiFxMySCIVEKCRCIdjzA5oVKWxK2iiRAAAAAElFTkSuQmCC",
"md5": "1bf0d144aa88eee8e49462fd2b644b06"
}
}
纯欠骂
/**PHP * 实际测试中发现部分格式企微识别有误 也可能是图片本身问题 没详尽研究 * 未通过 PNG image data, 1500 x 800, 8-bit gray+alpha, non-interlaced * 通过 JPEG image data, JFIF standard 1.01 */ $image = 'xx.jpeg'; $base64 = base64EncodeImage($image); $md5 = md5_file($image); function base64EncodeImage($image_file) { $image_data = fread(fopen($image_file, 'rb'), filesize($image_file)); return base64_encode($image_data); }
md5 和base64 生成及请求
imgkit.from_string(mail_content, 'downloads/111.png' , options={"encoding": "UTF-8"})
f = open('downloads/111.png', 'br')
fcont = f.read()
m2 = hashlib.md5(fcont)
md5_val = m2.hexdigest()
base64_data=str(base64.b64encode(fcont),encoding='utf-8')
r=requests.post(url,data={"msgtype":"image","image":{"base64":base64_data,"md5":md5_val}})
把base64图片内容里的换行符清空了replaceAll("\r|\n", "")
检查下base64中 \r\n的。会影响校验
// 这是java代码可以直接用的参考
import org.apache.commons.codec.digest.DigestUtils;// 重要依赖
@Test
public void Test2() throws Exception {
String purl = "图片url地址";
URL url = new URL(purl);
// 打开连接
URLConnection connection = url.openConnection();
try (
// 获取输入流
InputStream inputStream = connection.getInputStream();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
){
StreamUtils.copy(inputStream, outputStream);
// 发送post请求
String rurl = "https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=机器人key";
// 设置请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
// 创建请求体
Map<String, Object> image = new HashMap<>();
//关键步骤
image.put("base64", Base64.getEncoder().encodeToString(outputStream.toByteArray()).replaceAll("[\r\n]", ""));
image.put("md5", DigestUtils.md5Hex(outputStream.toByteArray()));
Map<String, Object> requestBody = new HashMap<>();
requestBody.put("msgtype", "image");
requestBody.put("image", image);
// 创建 HttpEntity 对象,包含请求头和请求体
HttpEntity<Map<String, Object>> entity = new HttpEntity<>(requestBody, headers);
// 发送 POST 请求
ResponseEntity<String> response = restTemplate.postForEntity(rurl, entity, String.class);
// 打印响应信息
System.out.println("Response Status Code: " + response.getStatusCode());
System.out.println("Response Body: " + response.getBody());
} catch (RestClientException e) {
throw new RuntimeException(e);
}
}
import org.apache.commons.codec.digest.DigestUtils; byte[] bytes = FileUtils.readFileToByteArray(new File("D:\\fsdownload\\bb.jpg")); String md5 = DigestUtils.md5Hex(bytes); //java 的方式
java 版代码,【坑点】转base64后要把\r\n替换掉,实测有效
URL url = new URL(sendMessageContent.getImage()); byte[] imageBytes = IoUtil.readBytes(url.openStream()); String imageBase64Str = Base64.getEncoder().encodeToString(imageBytes) .replaceAll("[\r\n]", ""); String md5 = MD5.create().digestHex(imageBytes);
markdown都不支持图片链接,什么时候支持啊,太👎了