C # develop WeChat portals and applications (19)-send messages to WeChat enterprise accounts (text, images, files, voice, video, text messages, etc ),

Source: Internet
Author: User

C # development portal and application (19)-sending of enterprise numbers (text, images, files, voice, video, text messages, etc ),

As we know, enterprise numbers are mainly generated for enterprise needs. Therefore, internal message communication is very important, and the number of messages sent and replied should be considerable, especially for large enterprises, therefore, you can use the enterprise ID to communicate Internal messages. Enterprise numbers are suitable for internal enterprise environments because they focus on security and have unlimited messages. This article describes how to use enterprise numbers to send messages, such as text, images, files, voice, video, and text messages.

1. Enterprise ID features

The Enterprise ID has the following features:

1) focus on security

-Only Members in the enterprise address book can pay attention to the enterprise number, and ensure the security of internal information of the enterprise by virtue of hierarchical administrators and confidential messages.

Enterprises can set up their own identity to authenticate the registrant and perform secondary security verification to ensure the security of enterprise information usage and transmission.

If an employee leaves the company, the enterprise administrator can delete the Member from the address book. The Member is automatically removed from the enterprise account and the enterprise account history is cleared.

2) configurable applications

-An enterprise can configure multiple service numbers on its own to connect to different enterprise application systems. Only authorized enterprise members can use the corresponding service numbers.

3) unlimited messages

-Unlimited message sending and comprehensive management interfaces and native capabilities are provided to adapt to complicated and personalized enterprise application scenarios.

Enterprises can send messages to employees,Unlimited message volume.

4) easier to use

-Enterprise numbers have unified message portals, allowing you to conveniently manage enterprise numbers. The address book can also directly access applications in the enterprise account.

 

2. Enterprise Account Management Interface content

Currently, the enterprise account content can be displayed in the following hierarchical chart, including material management, passive response message, address book management, custom menu, and so on. For details, see the figure below.

 

3. Handling of enterprise number messages and events

Like the public account, the enterprise account can be divided into message processing and event processing. The following two types of processing operations are available, the sent messages include text messages, image messages, file messages, video messages, voice messages, geographic text messages, text messages, and multimedia messages.

Event processing mainly involves following and canceling the event, as well as menu click and view operations, and reporting events by geographic location.

The two types of processing are shown in the following figure.

 

4. Enterprise number Message Management

In the enterprise management background, you can see the corresponding information exchange records, including text, images, and geographical locations, like the public accounts, as shown below.

 

Messages are classified into several types, including Text, Image, File, Voice, Video, and News) and MpNews.

Therefore, we need to define and encapsulate them separately. The following is their information object design diagram.

 

 

The official definition of enterprise number message sending is as follows:

Enterprises can send messages to employees,Unlimited message volume.

When an interface is called, the Https protocol and JSON data packet format are used. data packets do not need to be encrypted.

Currently, message types such as text, image, voice, video, file, and image/text are supported. In addition to the news type, other types of messages can be added with the confidentiality option, the confidential message will be watermark, and only the recipient can read.

 

Let's take the text message sent as an example. Its definition is as follows.

  • Text message
{   "touser": "UserID1|UserID2|UserID3",   "toparty": " PartyID1 | PartyID2 ",   "totag": " TagID1 | TagID2 ",   "msgtype": "text",   "agentid": "1",   "text": {       "content": "Holiday Request For Pony(http://xxxxx)"   },   "safe":"0"}

 

Parameters Required Description
Touser No UserID list (message recipients, separated by '| ). Special case: If it is specified as @ all, it will be sent to all Members who follow the enterprise application
Toparty No PartyID list. Multiple recipients are separated by '|. This parameter is ignored when touser is @ all.
Totag No TagID list. Multiple recipients are separated by '|. This parameter is ignored when touser is @ all.
Msgtype Yes Message type, which is fixed as text
Agentid Yes The id of the enterprise application, an integer. You can view it on the application settings page.
Content Yes Message Content
Safe No Indicates whether the message is confidential, 0 indicates no, and 1 indicates yes. The default value is 0.

 

 

Each message contains the following message, that is, their common attributes:

    touser": "UserID1|UserID2|UserID3",   "toparty": " PartyID1 | PartyID2 ",   "totag": " TagID1 | TagID2 ",   "msgtype": "text",   "agentid": "1",

Therefore, we can define a base class to facilitate carrying the common information.

/// <Summary> /// basic message content of the message sent by the enterprise ID /// </summary> public class CorpSendBase {// <summary> // UserID list (Message recipient, multiple receivers are separated by '| ). Special case: If it is specified as @ all, it will send // </summary> public string touser {get; set ;} /// <summary> /// PartyID list. Multiple recipients are separated by '|. When touser is @ all, ignore this parameter /// </summary> public string toparty {get; set ;}/// <summary> /// TagID list, multiple recipients are separated by '|. When touser is @ all, ignore this parameter // </summary> public string totag {get; set ;} /// <summary> /// Message Type // </summary> public string msgtype {get; set ;} /// <summary> /// Enterprise Application id, which is an integer. You can view the public string agentid {get; set ;}/// <summary> /// on the application settings page to check whether the message is a confidential message, 0 indicates no, 1 indicates yes, default 0 // </summary> [JsonProperty (NullValueHandling = NullValueHandling. ignore)] public string safe {get; set ;}}

Then other messages can inherit the base class one by one, as shown below.

It will eventually form the following inheritance relationship diagram.

 

5. definition and implementation of message Interfaces

After defining the relevant sending object, we can define its unified sending interface, as shown below.

/// <Summary> /// definition of the enterprise Message Management interface /// </summary> public interface ICorpMessageApi {/// <summary> /// send a message. /// The administrator must have the permission to view the recipients touser, toparty, and totag. Otherwise, this call fails. /// </Summary> /// <param name = "accessToken"> </param> /// <returns> </returns> CommonResult SendMessage (string accessToken, corpSendBase data );}

Finally, messages of the text type are implemented according to the interface definition. The implementation code is as follows. Note: sending ProcessNoCall the Encryption Class for encryption.

/// <Summary> /// enterprise Message Management Implementation class /// </summary> public class CorpMessageApi: ICorpMessageApi {/// <summary> /// send a message. /// The administrator must have the permission to view the recipients touser, toparty, and totag. Otherwise, this call fails. /// </Summary> /// <param name = "accessToken"> </param> /// <returns> </returns> public CommonResult SendMessage (string accessToken, corpSendBase data) {CommonResult result = new CommonResult (); string urlFormat = "https://qyapi.weixin.qq.com/cgi-bin/message/send? Access_token = {0} "; var url = string. format (urlFormat, accessToken); var postData = data. toJson (); // data does not need to be encrypted to send CorpSendResult sendResult = CorpJsonHelper <CorpSendResult>. convertJson (url, postData); if (sendResult! = Null) {result. success = (sendResult. errcode = CorpReturnCode. request successful); result. errorMessage = string. format ("invaliduser: {0}, invalidparty: {1}, invalidtag: {2}", sendResult. invaliduser, sendResult. invalidparty, sendResult. invalidtag) ;}return result ;}}
6. Message sending operations and actual results

After defining the corresponding sending objects, we can perform unified message sending operations, including text, images, files, voice, and other types of messages, note that some messages need to be uploaded to the server and sent according to mediaId.

The operation code for sending text and images is as follows.

Private void btnSendText_Click (object sender, EventArgs e) {// send text content ICorpMessageApi bll = new CorpMessageApi (); CorpSendText text = new CorpSendText ("API Chinese test (http://www.iqidi.com )"); text. touser = "wuw.cong"; text. toparty = "4"; // department ID text. totag = "0"; text. safe = "0"; text. agentid = "0"; CommonResult result = bll. sendMessage (token, text); if (result! = Null) {Console. WriteLine ("Send message: {0} {1} {2}", text. text. content, (result. Success? "Successful": "failed"), result. ErrorMessage) ;}} private void btnSendImage_Click (object sender, EventArgs e) {btnUpload_Click (sender, e); if (! String. isNullOrEmpty (image_mediaId) {// ICorpMessageApi bll = new CorpMessageApi (); CorpSendImage image = new CorpSendImage (image_mediaId); CommonResult result = bll. sendMessage (token, image); if (result! = Null) {Console. WriteLine ("Send image message: {0} {1} {2}", image_mediaId, (result. Success? "Successful": "failed"), result. ErrorMessage );}}}

Finally, the effect on the enterprise number is as follows, including text testing, file testing, graphic testing, and voice testing.

 

 

If you are interested in this series of C # development portals and applications, you can follow my other articles as follows:

C # development portal and application (18)-member management for enterprise address book management and development

C # development portal and application (17)-department management for enterprise address book management and development

C # development portal and application (16)-enterprise number configuration and use

C # development portal and application (15)-added the scan, image sending, and geographic location functions in the menu

C # development portal and application (14)-use redirection in the menu to obtain user data

C # development portal and application (13)-use geographic location Extension

C # development portal and application (12)-use voice processing

C # development portal and application (11)-menu presentation

C # development portal and application (10) -- synchronize user group information in the management system

C # development portal and application (9)-portal menu management and submission to server

C # development portal and application (8)-portal application management system function Introduction

C # development portal and application (7)-Multi-customer service functions and development integration

C # development portal and application (6)-portal menu management operations

C # development portal and application (5) -- User Group Information Management

C # development portal and application (4) -- Focus on the user list and detailed information management

C # development portal and application (3) -- Response to text messages and text messages

C # development portal and application (2) -- Message Processing and response

C # development portal and application (1) -- getting started with Interfaces


C :\

Yes

Refer to this to clean up the C drive:
1. Disable System Restoration: My computer properties/System Restoration/disable System Restoration on all disks, but I will not be able to use system restoration in the future!
2. Disable System sleep: Control Panel/Power Supply/sleep/remove the check before starting system sleep
3. move the virtual memory, my computer properties/advanced/performance/settings/advanced/change/select the C disk, that is, the system disk, select the no-score page, and then set the virtual memory to its disk, A disk with more disk space remaining, such as D, E, and F. set to 1.5 ~ of memory ~ 2.5 times. The size can be set to the same!
5. Clear temporary IE folders, internet Options, and delete temporary and offline files.
6. delete system logs and program logs, my computer/control panel/management tools/Computer Management/Event Viewer/application, right-click/clear events, and clear system logs in sequence
7. Clear system cache: 2000 all files in the system: C: \ WINNT \ system32 \ dllcache
The XP system is: C: \ windows \ system32 \ dllcache all files under the system cache (open my computer/tool/file and Folder Options/hide the protected system file hook off to hide all files on the hook) ). You can also run the sfc.exe/purgecache command to automatically delete the file.
8. Clear the recycle bin
9. delete the files under c: \ windows \ SoftwareDistribution \ Download (the files downloaded when the system is updated are useless if you have installed the updates)
10. Delete all directories under c: \ windows \ RegisteredPackages
11. Delete all Files under C: \ WINDOWS \ Downloaded Program Files
12. view the hidden files that are known to be protected by the system in my computer folder option, and check all the files.
13. Delete c: \ windows \ All files with $8882305 $ (backup files after system update)

Zhidao.baidu.com/question/11035955.html
Zhidao.baidu.com/question/12223613.html
Zhidao.baidu.com/question/14874715.html
... The remaining full text>

C :\

Yes

Refer to this to clean up the C drive:
1. Disable System Restoration: My computer properties/System Restoration/disable System Restoration on all disks, but I will not be able to use system restoration in the future!
2. Disable System sleep: Control Panel/Power Supply/sleep/remove the check before starting system sleep
3. move the virtual memory, my computer properties/advanced/performance/settings/advanced/change/select the C disk, that is, the system disk, select the no-score page, and then set the virtual memory to its disk, A disk with more disk space remaining, such as D, E, and F. set to 1.5 ~ of memory ~ 2.5 times. The size can be set to the same!
5. Clear temporary IE folders, internet Options, and delete temporary and offline files.
6. delete system logs and program logs, my computer/control panel/management tools/Computer Management/Event Viewer/application, right-click/clear events, and clear system logs in sequence
7. Clear system cache: 2000 all files in the system: C: \ WINNT \ system32 \ dllcache
The XP system is: C: \ windows \ system32 \ dllcache all files under the system cache (open my computer/tool/file and Folder Options/hide the protected system file hook off to hide all files on the hook) ). You can also run the sfc.exe/purgecache command to automatically delete the file.
8. Clear the recycle bin
9. delete the files under c: \ windows \ SoftwareDistribution \ Download (the files downloaded when the system is updated are useless if you have installed the updates)
10. Delete all directories under c: \ windows \ RegisteredPackages
11. Delete all Files under C: \ WINDOWS \ Downloaded Program Files
12. view the hidden files that are known to be protected by the system in my computer folder option, and check all the files.
13. Delete c: \ windows \ All files with $8882305 $ (backup files after system update)

Zhidao.baidu.com/question/11035955.html
Zhidao.baidu.com/question/12223613.html
Zhidao.baidu.com/question/14874715.html
... The remaining full text>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.