Skip to content

Commit

Permalink
修复webhook失败的bug
Browse files Browse the repository at this point in the history
  • Loading branch information
weichaoduo committed Jan 23, 2022
1 parent e2b5fb3 commit ac21ef2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
19 changes: 14 additions & 5 deletions bin/swoole_server.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
echo "Send mail started \n";
sendMail($serv, $sendArr);
}
if ($cmd == 'webhookpost') {
if ($cmd == 'webhookpost' || $cmd=='webhookhelper.post') {
echo "webhook post started \n";
print_r($sendArr);
webhookPost($serv, $sendArr);
Expand Down Expand Up @@ -359,10 +359,10 @@ function webhookPost($serv ,$sendArr)
$pushArr['webhook_id'] = (int)$sendArr['webhook_id'];
$pushArr['event_name'] = $sendArr['event_name'];
$pushArr['url'] = $sendArr['url'];
$pushArr['data'] = $sendArr['data'];;
$pushArr['data'] = json_encode($sendArr['json']);
$pushArr['status'] = WebHookLogModel::STATUS_READY;
$pushArr['time'] = time();
$pushArr['user_id'] = (int)$sendArr['user_id'];
$pushArr['user_id'] = (int)$sendArr['current_user_id'];
$pushArr['err_msg'] = '';
// 0准备;1执行成功;2队列中;3出队列后执行失败
$webhooklogModel = new WebHookLogModel();
Expand All @@ -375,10 +375,19 @@ function webhookPost($serv ,$sendArr)
} else {
$pushArr['log_id'] = 0;
}
$dataArr = $sendArr;
$timeout = $dataArr['timeout'];
$logId = (int)$dataArr['log_id'];
unset($dataArr['url'], $dataArr['timeout'],$dataArr['log_id']);
foreach ($dataArr as $key => $item) {
if(!is_string($item)){
$dataArr[$key] = json_encode($item);
}
}
$ch = curl_init($pushArr['url']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $pushArr['data'] );
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataArr );
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$body = curl_exec($ch);
//echo $body;
Expand Down
1 change: 1 addition & 0 deletions plugin/webhook/event/WebhookSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public function post(CommonPlacedEvent $event)
}
$postData['secret_token'] = $webhook['secret_token'];
$postData['timeout'] = $webhook['timeout'];
$postData['webhook_id'] = $webhook['id'];
$postData['url'] = $webhook['url'];
$postDataStr = http_build_query($postData);
$logArr = [];
Expand Down

0 comments on commit ac21ef2

Please sign in to comment.