企业微信机器人Javascript调用例子

发布时间 2023-09-22 14:58:59作者: knva
   const key = ""
   const oWX_URL = 'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key='+key;
                const sent_msg = {
                    'msgtype': 'text',
                    'text': {
                        'content': '已完成!'
                    }
                };

                const headers = {
                    'Content-Type': 'application/json'
                };

                fetch(oWX_URL, {
                    method: 'POST',
                    headers: headers,
                    body: JSON.stringify(sent_msg)
                })
                    .then(response => {
                    if (!response.ok) {
                        throw new Error('Network response was not ok');
                    }
                    return response.json();
                })
                    .then(data => {
                    // Handle the response data here
                })
                    .catch(error => {
                    console.error('There was a problem with the fetch operation:', error);
                });