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
上传文件
中文名称乱码
消息推送
Article Directory
- SAP ABAP Enterprise WeChat Server API > Message Push > Send Application Message > File Message: Upload Temporary Material with Garbled Chinese Name [Unresolved, to be updated]
-
- 1 Enterprise micro server API
- 2 The Chinese name is garbled
- 3 Problem Analysis Based on ABAP Implementation
- 4 Postman test cases and request content tracking
- 5 Some reference articles for the solution process
- 6 How to solve it in JAVA?
- 7 some useless records
- 8 Raise a case in the Qiwei developer community
- 9 summary
- other
1 Enterprise micro server API
API 按调用次序:
- (1) Enterprise WeChat Developer Center -> Server API -> Development Guide -> Get access_token
- (2) Enterprise WeChat Developer Center -> Server API -> Material Management -> Upload Temporary Material
- (3) Enterprise WeChat Developer Center -> Server API -> Message Push -> Send Application Message -> File Message
2 The Chinese name is garbled
不影响打开,但影响实际应用!
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_FILENAME
it 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
- Stack Overflow > how to set chinese filename correctly for different browsers when download file
- SAP Community > ABAP HTTP body Chinese characters garbled code
Among them, there are some sayings here that I find very interesting,
按照这篇社区文章的说法,基本结论就是依赖服务端的处理。
6 How to solve it in JAVA?
- Upload using the MultipartEntityBuilder class
//解决企业微信中文乱码问题,设置编码格式
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"
,
7 some useless records
- SPAD set spool character set, code page
- SAP LOGON > Properties > Code Page
- IF_HTTP_UTILITY~GET_LOGON_CHARSET
- Change the character set of the application server to UTF-8 ???
Do not try, out of bounds, but attach possible operations,
SAP Help Portal (Documentation) > select the server default character set - IF_HTTP_UTILITY~ESCAPE_URL
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,
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.