-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
document.getElementById('send-message-form').addEventListener('submit', function(event) { | ||
event.preventDefault(); // 阻止表单默认提交行为 | ||
|
||
// 获取输入的值 | ||
const appToken = document.getElementById('appToken').value; | ||
const topicId = document.getElementById('topicId').value; | ||
const message = document.getElementById('message').value; | ||
|
||
// 构建请求体 | ||
const requestBody = { | ||
appToken: appToken, | ||
content: message, | ||
topicIds: [topicId], | ||
contentType: 2, | ||
verifyPayType: 0 | ||
}; | ||
|
||
// 转换为JSON字符串 | ||
const requestData = JSON.stringify(requestBody); | ||
|
||
// 模拟发送请求 | ||
fetch('https://wxpusher.zjiecode.com/api/send/message', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json' | ||
}, | ||
body: requestData | ||
}) | ||
.then(response => { | ||
if (response.ok) { | ||
return response.json(); // 如果响应成功,解析JSON | ||
} else { | ||
throw new Error('Network response was not ok.'); | ||
} | ||
}) | ||
.then(data => { | ||
document.getElementById('status-message').textContent = `发送成功: ${data.code}`; | ||
}) | ||
.catch(error => { | ||
document.getElementById('status-message').textContent = `发送失败: ${error}`; | ||
}); | ||
}); |