|
- <?php
- /**
- * Created by PhpStorm.
- * User: Qiu Song
- * Date: 2016/11/07
- * Time: 15:00
- */
- header("Content-type:text/html;charset=utf-8");
- require_once __DIR__.'/../Common/Mysql.php';
- date_default_timezone_set('Asia/Shanghai');
-
- $current_time = date("Y-m-d H:i:s");
-
- $pdo=conn();
- $sql = " SELECT id,send_url,send_data,send_result,success_flag ".
- " FROM outside_send_url ".
- " WHERE success_flag = 0 ";
- $result=$pdo->query($sql);
- if( false == $result ) {
- echo " NO DATA";
- exit();
- }
- $rowset = $result->fetchAll();
- $result->closeCursor();
-
- foreach( $rowset as $row_info ) {
- $send_url = $row_info["send_url"];
- $send_data = $row_info["send_data"];
- $send_result = send_post_json( $send_url, $send_data );
- $success_flag = 0;
- if( $send_result != false && $send_result[0] == 200 && isset($send_result[1]) ) {
- $result_array = json_decode($send_result[1],true);
- if( $result_array["status"] == 0 ) {
- $success_flag = 1;
- }
- }
- $send_result_txt = json_encode($send_result);
- $pdo_update = conn();
- $sql_update = " UPDATE outside_send_url set success_flag={$success_flag},send_time='{$current_time}',send_result='{$send_result_txt}' WHERE id={$row_info["id"]}";
- $pdo_update->exec($sql_update);
- }
-
- echo $current_time." END";
- exit();
-
- function send_post_json($url, $data_string) {
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_POST, 1);
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
- curl_setopt($ch, CURLOPT_HTTPHEADER, array(
- 'Content-Type: application/json; charset=utf-8',
- 'Content-Length: ' . strlen($data_string))
- );
- ob_start();
- curl_exec($ch);
- $return_content = ob_get_contents();
- ob_end_clean();
-
- $return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
- return array($return_code, $return_content);
- }
|