SAP ABAP Enterprise WeChat Server API > Message Push > Send Application Message > File Message: Upload Temporary Material with Garbled Chinese Name [Unresolved, to be updated]

SAP ABAP Enterprise WeChat Server API > Message Push > Send Application Message > File Message: Upload Temporary Material with Garbled Chinese Name [Unresolved, to be updated]

Introduction: The Chinese name of the temporary material uploaded by the enterprise WeChat is garbled, and the ABAP implementation problem has not been solved. It should be no problem to implement it in languages ​​​​such as JAVA. This article is some of my development records, and I would like to leave it to my colleagues to continue to study.

keywords:SAP ABAP 企业微信 服务端 API 上传文件 中文名称乱码 消息推送


1 Enterprise micro server API

API 按调用次序:

2 The Chinese name is garbled

不影响打开,但影响实际应用!
insert image description here

3 Problem Analysis Based on ABAP Implementation

  • Example of an official request
POST https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=accesstoken001&type=file HTTP/1.1
Content-Type: multipart/form-data; boundary=-------------------------acebdf13572468
Content-Length: 220
---------------------------acebdf13572468
Content-Disposition: form-data; name="media";filename="wework.txt"; filelength=6
Content-Type: application/octet-stream
mytext
---------------------------acebdf13572468--
  • ABAP request example (raw request)
  lv_name = lv_filename.
  lv_value = 'form-data; name="media"; filename="' && lv_name && '"'.
  call method lo_part->set_header_field
    exporting
      name  = 'content-disposition'
      value = lv_value.
  • ABAP request example (improved in the most likely correct direction)
    尝试字符集编码识别,结果失败。
  lv_name = lv_filename.
  lv_name = escape( val = lv_name format = cl_abap_format=>e_uri_full ).
  lv_value = `form-data; name="media"; filename*=UTF-8''` && lv_name.
  call method lo_part->set_header_field
    exporting
      name  = 'Content-Disposition'
      value = lv_value.

Trying to use IF_HTTP_UTILITY~CONTENT_DISPOSITION_FILENAMEit is invalid, and SAP Support has several Notes that need to be implemented, such as 2260256, and it is discarded.
[ filename*=UTF-8'' && lv_name ] 这类处理其实依赖服务端是否支持解析。

4 Postman test cases and request content tracking

The Postman test result is normal, and the Chinese name is OK!

5 Some reference articles for the solution process

6 How to solve it in JAVA?

  • Upload using the MultipartEntityBuilder class
    insert image description here
         //解决企业微信中文乱码问题,设置编码格式
       MultipartEntityBuilder builder = MultipartEntityBuilder.create().setMode(HttpMultipartMode.RFC6532);
       builder.addBinaryBody("media", file, ContentType.DEFAULT_BINARY, encodedFilename);
       HttpEntity reqEntity = builder.build();
       // 定义数据分隔线
       httpPost.setEntity(reqEntity);
       httpResponse = httpPost.execute(httpMethod);
  • How to implement the JAVA in the figure below in ABAP? In particular enc:"UTF-8",
    insert image description here

7 some useless records

8 Raise a case in the Qiwei developer community

Enterprise Micro Developer Community> The Chinese name of the file message sent by the server API is garbled?
There are many homogeneous problems on the right side,
insert image description here
insert image description here

9 summary

  • 我真诚的建议:转向 JAVA 平台发布 API 服务跳板。
  • Implement JAVA functions in ABAP (see Section 6 for details).
  • Qiwei should not support parsing, whether it is re-specifying the header field of filename or character set conversion.
  • Enterprise WeChat's technical support is really terrible! You can't find a human customer service, you can only ask questions in the case mode, which is completely inefficient. When you encounter problems, you may even have the idea of ​​​​changing partners and abandoning the dark for the bright.
  • This problem broke me down. If you solve this problem in ABAP, be sure to reply me in the message to watch! Thank you in advance.

对酒当歌,人生几何!譬如朝露,去日苦多。


other

My WeChat group, QQ group and other publishing platforms.

Provide long-term development and operation and maintenance services.

Guess you like

Origin blog.csdn.net/libin961797440/article/details/132053900