/** * 将对象转换为数组 * * @param object $obj 数组对象 * @return array */ function dr_object2array($obj) { $_arr = is_object($obj) ? get_object_vars($obj) : $obj; if ($_arr && is_array($_arr)) { foreach ($_arr as $key => $val) { $val = is_array($val) || is_object($val) ? dr_object2array($val) : $val; $arr[$key] = $val; } } return $arr; }
/** * 短信发送 * * @param string $mobile * @param string $content * @return bool */ public function sendsms($mobile, $content, $tid) { if (!$mobile || !$content) { return FALSE; } $file = FCPATH . 'config/sms.php'; if (!is_file($file)) { return FALSE; } if (!$tid) { $tid = "1"; } $config = (require_once $file); if ($config['third']) { $this->load->helper('sms'); if (function_exists('my_sms_send')) { $result = my_sms_send($mobile, $content . '【' . $config['note'] . '】'); } else { return FALSE; } } else { $result = dr_catcher_data('http://www.omooo.com/sms.php?c=send&tid=' . $tid . '&uid=' . $config['uid'] . '&key=' . $config['key'] . '&mobile=' . $mobile . '&content=' . $content . '&domain=' . trim(str_replace('http://', '', SITE_URL), '/') . '&sitename=' . SITE_NAME); if (!$result) { return FALSE; } $result = dr_object2array(json_decode($result)); //对象转换数组 } @file_put_contents(FCPATH . 'cache/sms_error.log', date('Y-m-d H:i:s') . ' [' . $mobile . '] [' . $result['msg'] . '] (' . str_replace(array(chr(13), chr(10)), '', $content) . ')' . PHP_EOL, FILE_APPEND); return $result; }
function fn_sendsms($mobile, $content) { if (!$mobile || !$content) { return FALSE; } $file = FCPATH . 'config/sms.php'; $config = is_file($file) ? string2array(file_get_contents($file)) : array(); $result = dr_catcher_data('http://sms.dayrui.com/index.php?uid=' . $config['uid'] . '&key=' . $config['key'] . '&mobile=' . $mobile . '&content=' . $content . '【' . $config['note'] . '】&domain=' . trim(str_replace('http://', '', SITE_URL), '/') . '&sitename=' . CMS_NAME); if (!$result) { return FALSE; } $result = dr_object2array(json_decode($result)); @file_put_contents(FCPATH . 'cache/sms.log', date('Y-m-d H:i:s') . ' [' . $mobile . '] [' . $result['msg'] . '] (' . str_replace(array(chr(13), chr(10)), '', $content) . ')' . PHP_EOL, FILE_APPEND); return $result; }