function slackApiExecute($url, $payload) { $headers = array(); $params = array('payload' => json_encode($payload)); $result = postRequest($url, $params, $headers); return $result; }
public function getSmsCode($phone, $tpl_id, $tpl_value) { $this->load->helper('sharesdk'); $api = $this->config->item('sms_api'); $key = $this->config->item('sms_apikey'); $response = postRequest($api, array('apikey' => $key, 'mobile' => $phone, 'tpl_id' => $tpl_id, 'tpl_value' => $tpl_value)); return $response; }
function setdisplay() { global $ACCESS_TOKEN, $json_input; $data = sprintf("access_token=%s&args=%s", $ACCESS_TOKEN, strval($json_input['dv'])); $res = postRequest($data, "setdisplay"); $json = json_decode($res, true); outputData(json_encode(array('status' => 1, 'dispval' => $json['return_value']))); }
function sendlove_toanother($userid, $username, $nickname, $isSuper, $toArg, $forArg, $priv) { // UTF-8 Encode passed parameters to preserve non-latin characters. $username = setEncoding($username); $nickname = setEncoding($nickname); $toArg = setEncoding($toArg); $forArg = setEncoding($forArg); if (enforceRateLimit('love', $userid)) { error_log("User " . $userid . " send love was rate limited."); return 'ratelimit'; } // Only super admins can send love to the guest account $to = mysql_real_escape_string(strtolower(trim($toArg))); if ($to == GUEST_USER && !$isSuper) { return 'guest'; } //Can't send love to self if ($to == $username) { return 'self'; } $sqlView = "SELECT company_id, skill, team FROM " . USERS . " WHERE id='" . $userid . "'"; $resView = mysql_query($sqlView); $rowView = mysql_fetch_array($resView); $company_id = $rowView['company_id']; $skill = $rowView['skill']; $team = $rowView['team']; $sqlView = "SELECT company_id FROM " . USERS . " WHERE username = '******'and removed = 0"; $resView = mysql_query($sqlView); $rowView = mysql_fetch_array($resView); $to_company = $rowView['company_id']; $company = $company_id == $rowView['company_id'] ? ", company_id='" . $company_id . "'" : ""; $private = $priv ? ',private=1' : ''; //$allowed_tags = array(); // no tags are currently allowed in the 'forArg' $for = $forArg; //strip_tags($forArg); // this sends the actual email if (!sl_send_love($username, $nickname, $userid, $company_id, $to, $for, false, $priv)) { // false from sl_send_love means the user was outside the system return 'outside'; } $rc = 'ok'; $query = "insert into " . LOVE . " set giver='" . $username . "', receiver='" . addslashes($to) . "', skill='{$skill}', team='{$team}', why='" . addslashes($for) . "', at=now()" . $company . $private; $res = mysql_query($query); // See if the recipient is has a facebook id, if so we'll return a value so it can be handled. $resfb = mysql_query("select id, fb_id from " . USERS . " where username = '******'"); if (mysql_num_rows($resfb) > 0) { $rowfb = mysql_fetch_assoc($resfb); $fb_id = $rowfb['fb_id']; if (!empty($fb_id)) { $rc = array('facebook', $to, $for, $fb_id); } } if ($company_id == $to_company && $company_id == JOURNAL_API_COMPANY && !$priv) { $toNickname = getNickName($to); if (empty($toNickname)) { $toNickname = $to; } $for = stripslashes($for); $data = array(); $data['user'] = JOURNAL_API_USER; $data['pwd'] = sha1(JOURNAL_API_PWD); $data['message'] = $nickname . " to {$toNickname}: {$for}"; $prc = postRequest(JOURNAL_API_URL, $data); } return $rc; }
//throw new Exception("Error: unhandled mime-type [" + $mimeType + "]"); echo $fileContent; } $request = json_encode(new TorrentAddRequest($fileContent, true)); } else { $request = json_encode(new TorrentAddRequest($link, false)); } //send request $response = postRequest($url, $request, $header); //read header to change session id if necessary if (stripos($response['header'], "HTTP/1.1 409 Conflict") !== false) { $rows = explode("\n", $response['header']); $found = false; for ($i = 0; $i < count($rows) && $found == false; $i++) { $row = $rows[$i]; $chunks = explode(":", $row); if ($chunks[0] == "X-Transmission-Session-Id") { $sessionId = trim($chunks[1]); $_SESSION['transmission-session'] = $sessionId; $header[] = "X-Transmission-Session-Id: {$sessionId}"; $found = true; } } //repeat request with new session id if (isset($sessionId)) { $response = postRequest($url, $request, $header); } } //echo $response['header']; echo $response['body']; }
if (SERVERLIST_URL) { echo "Contacting " . SERVERLIST_URL . " to initiate server.\n"; // Install the server $request = postRequest(SERVERLIST_URL, ABSOLUTE_URL, array('action' => 'initialize', 'server' => ABSOLUTE_URL, 'visible' => SERVERLIST_VISIBLE ? 1 : 0)); if ($request && isset($request['id']) && isset($request['name'])) { $server->setServerName($request['id'], $request['name']); } } else { $server->setServerName(1, 'Dolumar'); } } else { if (SERVERLIST_URL) { echo "Contacting " . SERVERLIST_URL . " to update serverlist.\n"; echo "Generating request... "; $out = array('action' => 'update', 'server' => ABSOLUTE_URL, 'id' => $server->getServerId(), 'players' => $server->countTotalPlayers(), 'last24' => $server->countOnlineUsers(60 * 60 * 24), 'visible' => SERVERLIST_VISIBLE ? 1 : 0, 'version' => APP_VERSION, 'bigpoint' => defined('BIGPOINT_URL') ? BIGPOINT_URL : null); echo "done!\n"; print_r($out); echo "\n\n"; echo "Sending request...\n"; // Contact thze master server for an update $request = postRequest(SERVERLIST_URL, ABSOLUTE_URL, $out); if ($request && isset($request['name'])) { $server->updateServerName($request['name']); } } } // Update the daily $server->setLastDaily(); $server->updateStatus(); // Clean thze server $server->cleanServer();
function getUserLove($username, $fromUsername = "", $startDate = "", $endDate = "") { defineSendLoveAPI(); $params = array('action' => 'getlove', 'api_key' => LOVE_API_KEY, 'username' => $username, 'startDate' => $startDate, 'endDate' => $endDate, 'pagination' => 0); if ($fromUsername != "") { $params['fromUsername'] = $fromUsername; } $referer = (empty($_SERVER['HTTPS']) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['PHP_SELF']; $retval = json_decode(postRequest(LOVE_API_URL, $params, array(CURLOPT_REFERER, $referer)), true); if (isset($retval['status']) && $retval['status'] == "ok") { return $retval['data']; } else { return -1; } }
} } } } } else { if (isMatch($input[0], '/jobsdb')) { if (count($input) >= 2) { $keyword = implode(' ', array_slice($input, 1)); $resp = json_decode(postRequest('http://localhost:8080/jobsdb', array('keyword' => $keyword)))->text; sendMessage($id, $resp, '&disable_web_page_preview=true'); } else { sendMessage($id, 'Usage: /jobsdb keyword...'); } } else { if (isMatch($input[0], '/hkgolden')) { $resp = json_decode(postRequest('http://localhost:8080/hkgolden', array()))->text; sendMessage($id, $resp, '&disable_web_page_preview=true'); // sendMessage($id, "$senderFirstName 同事,請勿在上班時上高登。"); } else { if (isMatch($input[0], '/buddha')) { $con = connectDB(); $count = getSQLRows($con, 'SELECT count(1) ct FROM buddha')[0]['ct']; $num = rand(1, $count); $quote = getSQLRows($con, "SELECT quote from buddha where id = {$num}")[0]['quote']; sendMessage($id, $quote); } else { if (isMatch($input[0], '/bible')) { $con = connectDB(); $count = getSQLRows($con, 'SELECT count(1) ct FROM bible')[0]['ct']; $num = rand(1, $count); $quote = getSQLRows($con, "SELECT quote from bible where id = {$num}")[0]['quote'];
function validate_payment() { postRequest($_POST); }
public function populatePeers() { $peers = $this->getUserPeersIds(); $data = array('api_key' => REVIEW_API_KEY, 'action' => 'populate_peers', 'user_id' => $this->user_id); if (count($peers) > 0) { $i = 0; foreach ($peers as $peer) { $data["peers[{$i}]"] = $peer['id']; $i++; } } postRequest(REVIEW_API_URL, $data); }
/* PUT request to edit city */ $errMsg = putRequest("country/{$idCountry}/city/{$idCity}/"); } else { /* POST request to add city*/ $errMsg = postRequest("country/{$idCountry}/city/"); } } if (!empty($_POST['lanName'])) { $str = "Name={$_POST['lanName']}"; curl_setopt($curl, CURLOPT_POSTFIELDS, $str); if (!$switcher) { /* PUT request to edit language city */ $errMsg = putRequest("country/{$idCountry}/city/{$idCity}/language/{$idLan}/"); } else { /* POST request to add language*/ $errMsg = postRequest("country/{$idCountry}/city/{$idCity}/language"); } } } if (isset($_GET['del'])) { $id = abs((int) $_GET['id']); curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); switch ($_GET['del']) { case 'country': $errMsg = deleteRequest("country/{$id}/"); break; case 'city': $errMsg = deleteRequest("city/{$id}/"); break; case 'language': $idCity = abs((int) $_GET['id_city']);
include "../connect.php"; include "../utils.php"; // 配置项 $api = 'https://webapi.sms.mob.com/sms/verify'; $appkey = 'f24bd7349e2c'; $name = addslashes($_POST["name"]); $account = addslashes($_POST["account"]); $password = md5(addslashes($_POST["password"])); $code = addslashes($_POST["code"]); if ($name == "" || $account == "" || $password == "") { header("http/1.1 400 Bad Request"); $result["error"] = "name,account或password不能为空"; } else { //发送验证码 $response = postRequest($api, array('appkey' => $appkey, 'phone' => $account, 'zone' => '86', 'code' => $code)); $response_json = json_decode($response, true); if ($response_json['status'] == 200) { $query = "SELECT * FROM account WHERE account = '{$account}'"; $user = mysql_query($query); if ($row = mysql_fetch_assoc($user)) { header("http/1.1 400 Bad Request"); $result["error"] = $name . " 已被使用"; } else { $query = "INSERT INTO account ( name,account , password,manager ) VALUES ( '{$name}','{$account}','{$password}','0')"; if (mysql_query($query)) { $result["info"] = "注册成功"; } else { header("http/1.1 500 Internal Server Error"); $result["error"] = mysql_error(); }
exit; } // if the number of kicks before the update is greater than the amount after the update // then that means the patient never reached 10 kicks in an hour, so send an alert email // but disregard the case where people start from 0 and go to 1 kick if ($oldNumKicks >= $curNumKicks && $curNumKicksBeforeIncrement != 0 && $timesBeenEmailed < 1) { $data = array('email' => $patientEmail, 'subject' => 'Irregular Kick Count', 'textArgs' => json_encode(array('name' => $patientFirstName))); $user_group_admin_id = Group::getGroupAdminByUser($userId); $user_group_admin = User::findById($user_group_admin_id)->getAdditionalInfo(); $userGroupAdminEmail = $user_group_admin->email; $userGroupAdminName = $user_group_admin->first_name; $provider_data = array('email' => $userGroupAdminEmail, 'subject' => 'Patient With Irregular Kick Count', 'textArgs' => json_encode(array('patient_first_name' => $patientFirstName, 'patient_last_name' => $patientLastName, 'patient_phone_number' => $patientPhone, 'patient_email' => $patientEmail, 'patient_provider_name' => $providerName, 'admin_first_name' => $userGroupAdminName))); // send an email to the user $response = postRequest(AUTH_SERVER . '/emails/send-email/kick_tracker-inactive', $data); // send an email to the user's group's admin $provider_response = postRequest(AUTH_SERVER . '/emails/send-email/kick_tracker-admin_alert', $provider_data); if (!isset($response->status) || $response->status != 'success' || (!isset($provider_response->status) || $provider_response->status != 'success')) { Log::user("Error sending irregular kick count email"); exit; } // once email is sent, update the last time a kick email was sent User::updateKickEmailTime($userId); } if ($curNumKicks >= 10) { Log::user("Silently updating last sent email time so avoid getting a forgotten kick tracker email"); User::updateKickEmailTime($userId); } boldError("Success"); echo json_encode(array('status' => 'success', 'numKicks' => $curNumKicks, 'timesBeenEmailed' => $timesBeenEmailed)); } } elseif ($_SERVER['REQUEST_METHOD'] == 'GET') {
<?php header('Content-Type: application/json'); require_once 'include/functions.php'; require_once 'include/SessionCheck.php'; $sessionCheck = new SessionCheck(); //result variable $result = array('status' => 'error', 'messages' => array()); if ($sessionCheck->checkAjaxCall() == true) { if ($sessionCheck->checkKey(postRequest('hashkey'), sessionRequest('salt_value')) == true) { //added the verification on empty generated Captcha if (strtolower(postRequest('captcha')) !== strtolower(sessionRequest('captcha')) && sessionRequest('captcha') !== '') { array_push($result['messages'], 'error_captcha'); } if (!filter_var(postRequest('email'), FILTER_VALIDATE_EMAIL)) { array_push($result['messages'], 'error_email'); } } else { array_push($result['messages'], 'error'); } } else { array_push($result['messages'], 'error'); } if (count($result['messages']) == 0) { $result['status'] = 'ok'; } echo json_encode($result); exit;
/** *发送短信 *@param string $url 服务器地址 *@param string $ececcid 接入账户,非空 *@param string $password 接入密码,非空。 *@param string $msisdn 接收号码,多个用逗号隔开,非空。 *@param string $smscontent 短信内容,非空。长度不能超过500字符 *@param int $msgtype=5 短信类型,默认值为5。 *@param int $longcode="" 扩展码,可为空。 */ function SendSMS_HTTP($url, $ececcid, $password, $msisdn, $smscontent, $msgtype = 5, $longcode = "") { $post_string = "ececcid={$ececcid}&password={$password}&msisdn={$msisdn}&smscontent={$smscontent}&msgtype={$msgtype}&longcode={$longcode}"; return postRequest($url, $post_string); }
} $_result = postRequest($_url, $_params); if (substr_count($_result, "<failed>") != 0) { $_xml = simplexml_load_string($_result); $_error = $_xml->failed->message; $_form = "login"; } $_url = apiURL() . "/user.acl.update"; $_tmp = ""; foreach ($_REQUEST as $name => $value) { if (substr_count($name, 'pf_acl_') != 0) { $_tmp = $_tmp . str_replace("pf_acl_", "", $name) . "=" . $value . '&'; } } $_params = "sid=" . $_sid . "&realm=" . $_realm . "&acls=" . myUrlencode($_tmp); $_result = postRequest($_url, $_params); if (substr_count($_result, "<failed>") != 0) { $_xml = simplexml_load_string($_result); $_error = $_xml->failed->message; $_form = "login"; } } } } if (isset($_REQUEST['pf_next']) && $_REQUEST['pf_next'] != "") { $_formTab2 = $_formTab2 + 1; if ($_formTab == 1 && $_formTab2 > 3 || $_formTab == 2 && $_formTab2 > 6) { $_formTab = $_formTab + 1; $_formTab2 = 0; } if ($_formTab == 3) {
$user = checkToken(2, $result); if ($user == -1) { echo json_encode($result); return; } $id = addslashes($_POST["id"]); $type = addslashes($_POST["type"]); $brand = addslashes($_POST["brand"]); $drawing_number = addslashes($_POST["drawing_number"]); $avatar = addslashes($_POST["avatar"]); $note = addslashes($_POST["note"]); $picture = addslashes($_POST["picture"]); //将图片url转换成图片信息对象,再转换成json保存数据库 $pics = explode(",", $picture); foreach ($pics as $pic) { $image = postRequest($pic . "?imageInfo"); $image_json = json_decode($image, true); $image_json["url"] = $pic; $images[] = $image_json; } $images = json_encode($images); $sql = "SELECT * FROM part WHERE id = '{$id}'"; $sqlresult = mysql_query($sql); if ($row = mysql_fetch_assoc($sqlresult)) { if (!is_super($user) && $row["author_id"] != $user) { header("http/1.1 403 Forbidden"); $result["error"] = "用户权限不足"; echo json_encode($result); return; } $sql = "UPDATE part SET \n\t\ttype = '{$type}' , \n\t\tbrand = '{$brand}', \n\t\tdrawing_number = '{$drawing_number}', \n\t\tavatar = '{$avatar}', \n\t\tpicture = '{$images}',\n\t\tnote = '{$note}'\n\t\tWHERE id = '{$id}'";
* 发起一个post请求到指定接口 * * @param string $api 请求的接口 * @param array $params post参数 * @param int $timeout 超时时间 * @return string 请求结果 */ function postRequest($api, array $params = array(), $timeout = 30) { $ch = curl_init(); curl_setopt($ch, CURLOPT_PROXY, proxy); curl_setopt($ch, CURLOPT_URL, $api); // 以返回的形式接收信息 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // 设置为POST方式 curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params)); // 不验证https证书 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded;charset=UTF-8', 'Accept: application/json')); // 发送数据 $response = curl_exec($ch); // 不要忘记释放资源 curl_close($ch); return $response; } // 发送验证码 $response = postRequest($apiurl, array('appkey' => $appkey, 'phone' => '13989497004', 'zone' => '86', 'code' => '1234')); var_dump($response);
function sendFromJournal() { // Check that all required parameters exist if (empty($_POST['caller']) || empty($_POST['from']) || empty($_POST['to']) || empty($_POST['why'])) { $rsp['error'] = SL_BAD_CALL; respond($rsp); } // Prepare received data $to = mysql_real_escape_string(trim(setEncoding($_POST['to']))); $from = mysql_real_escape_string(trim(setEncoding($_POST['from']))); $why = smart_strip_tags(mysql_real_escape_string(trim(setEncoding($_POST['why'])))); $private = isset($_POST['priv']) && (int) $_POST['priv'] > 0; // Can't send love to self if (strtolower($to) == strtolower($from)) { $rsp['error'] = SL_NOT_COWORKER; respond($rsp); } // Check that to and from nicknames exist and find their data foreach (array('from', 'to') as $v) { $query = "select id, fb_id, username, nickname, company_id, skill, team " . "from " . USERS . " where nickname='" . ${$v} . "' and removed = 0"; $res = mysql_query($query); $line = mysql_fetch_array($res, MYSQL_ASSOC); if ($res && $line) { ${$v} = $line; } else { $rsp['error'] = SL_UNKNOWN_USER; respond($rsp); } } // Check rate limit if (enforceRateLimit('love', $from['id'])) { error_log("User " . $from['id'] . " send love was rate limited."); $rsp['error'] = SL_RATE_LIMIT; respond($rsp); } // Send love if (!sl_send_love($from['username'], $from['nickname'], $from['id'], $from['company_id'], $to['username'], $why, false, $private)) { $rsp['error'] = SL_SEND_FAILED; respond($rsp); } // Record love in database $company = $to['company_id'] == $from['company_id'] ? ", company_id={$to['company_id']}" : ""; $priv_str = $private ? ', private=1' : ''; $query = "insert into " . LOVE . " set giver='{$from['username']}', receiver='{$to['username']}', " . "skill='{$from['skill']}', team='{$from['team']}', why='{$why}', at=now()" . $company . $priv_str; $rsp['status'] = SL_OK; $rsp['error'] = SL_NO_ERROR; $rsp['info'] = $query; if (!mysql_query($query)) { error_log("Add Love.err:" . mysql_error()); $rsp['error'] = SL_DB_FAILURE; respond($rsp); } // See if the recipient is has a facebook id, if so we'll return a value so it can be handled. // if (!empty($to['fb_id'])) { // $rc = array('facebook', $to['username'], $why, $to['fb_id']); // } // Make love notice in journal if ($to['company_id'] == JOURNAL_API_COMPANY && !$private) { $data = array('user' => JOURNAL_API_USER, 'pwd' => sha1(JOURNAL_API_PWD), 'message' => "{$from['nickname']} to {$to['nickname']}: {$why}"); $journal_rsp = postRequest(JOURNAL_API_URL, $data); $journal_rsp = trim($journal_rsp); if ($journal_rsp != 'ok') { $rsp['status'] = SL_WARNING; $rsp['error'] = SL_JOURNAL_FAILED; $rsp['info'] = $journal_rsp; respond($rsp); } } }