public function createUser($user) { $user = coll_elements(array('username', 'password', 'role'), $user); $exist = $this->getUser($user['username'], true); if (!empty($exist)) { return error(-1, '用户名已经存在, 请返回修改'); } $user['salt'] = util_random(8); $user['status'] = self::STATUS_ENABLED; $user['password'] = Utility::encodePassword($user['password'], $user['salt']); $ret = $this->table('__USR_USERS__')->data($user)->add(); if (!empty($ret)) { return $this->getLastInsID(); } return error(-2, '保存用户数据失败, 请稍后重试'); }
public function createAction() { if (IS_POST) { $input = $this->validateForm(); $user = $this->acl->getUser($input['username'], true); if (!empty($user)) { $this->error('用户名已经存在, 请返回修改'); } $input['salt'] = util_random(8); $input['password'] = Utility::encodePassword($input['password'], $input['salt']); $ret = $this->acl->table('__USR_USERS__')->data($input)->add(); if (empty($ret)) { $this->error('保存新增用户失败, 请稍后重试'); } else { $this->success('成功新增管理用户'); exit; } } $this->display('form'); }
public function exec($message, $processor) { if (!empty($processor)) { $b = new Bridge(null); $platform = $b->getOne($processor['id'], true); $body = $this->toRequestXml($message); $url = $platform['url']; if (!strpos($url, '?') == -1) { $url .= '?'; } else { $url .= '&'; } $params = array('timestamp' => TIMESTAMP, 'nonce' => util_random(10, 1)); $signParams = array($platform['token'], $params['timestamp'], $params['nonce']); sort($signParams, SORT_STRING); $params['signature'] = sha1(implode($signParams)); $url .= http_build_query($params, '', '&'); $ret = Net::httpPost($url, $body); if (!empty($ret)) { return $this->toPacket($ret); } } }
/** * @param $log * @return js payment object */ public function payWeixin($log) { self::loadSettings(); $setting = C('PAY'); $pay = $setting[self::OPT_WEIXIN]; $a = new Account(); $account = $a->getAccount($pay['account']); $pay['appid'] = $account['appid']; $pay['secret'] = $account['secret']; $wOpt = array(); $m = new Member(); $fan = $m->fetchFan($log['uid'], $pay['account']); $package = array(); $package['appid'] = $pay['appid']; $package['mch_id'] = $pay['mchid']; $package['nonce_str'] = util_random(8); $package['body'] = $log['title']; $package['attach'] = $log['plid']; $package['out_trade_no'] = md5($log['plid']); $package['total_fee'] = $log['fee'] * 100; $package['spbill_create_ip'] = get_client_ip(); $package['time_start'] = date('YmdHis', TIMESTAMP); $package['time_expire'] = date('YmdHis', TIMESTAMP + 600); $package['notify_url'] = __HOST__ . U('wander/payment/weixin/t/notify'); $package['trade_type'] = 'JSAPI'; $package['openid'] = $fan['openid']; ksort($package, SORT_STRING); $string1 = ''; foreach ($package as $key => $v) { $string1 .= "{$key}={$v}&"; } $string1 .= "key={$pay['key']}"; $package['sign'] = strtoupper(md5($string1)); $dat = util_2xml($package); $response = Net::httpPost('https://api.mch.weixin.qq.com/pay/unifiedorder', $dat); if (is_error($response)) { return $response; } $xml = '<?xml version="1.0" encoding="utf-8"?>' . $response; $dom = new \DOMDocument(); if (!$dom->loadXML($xml)) { return error(-1, 'error response'); } $xpath = new \DOMXPath($dom); if ($xpath->evaluate("string(//xml/return_code)") == 'FAIL') { return error(-2, $xpath->evaluate("string(//xml/return_msg)")); } if ($xpath->evaluate("string(//xml/result_code)") == 'FAIL') { return error(-3, $xpath->evaluate("string(//xml/err_code_des)")); } $prepayid = $xpath->evaluate("string(//xml/prepay_id)"); $wOpt['appId'] = $pay['appid']; $wOpt['timeStamp'] = TIMESTAMP; $wOpt['nonceStr'] = util_random(8); $wOpt['package'] = 'prepay_id=' . $prepayid; $wOpt['signType'] = 'MD5'; ksort($wOpt, SORT_STRING); $string = ''; foreach ($wOpt as $key => $v) { $string .= "{$key}={$v}&"; } $string .= "key={$pay['key']}"; $wOpt['paySign'] = strtoupper(md5($string)); return $wOpt; }
/** * 登记当前消息中的用户资料, 在派生类中实现时, 应至少传递 openid, unionid, subscribe, subscribetime, unsubscribetime, tag * @param $message * @return boolean */ public function booking($message) { $account = $this->getAccount(); if (!empty($account) && !empty($message)) { $fan = coll_elements(array('openid', 'unionid', 'subscribe', 'subscribetime', 'unsubscribetime', 'tag'), $message); $fan['platformid'] = $account['id']; $condition = '`platformid`=:platformid AND `openid`=:openid'; $pars = array(); $pars[':platformid'] = $fan['platformid']; $pars[':openid'] = $fan['openid']; $m = new Model(); $fanid = $m->table('__MMB_MAPPING_FANS__')->where($condition)->bind($pars)->getField('`fanid`'); if (empty($fanid)) { $fan['uid'] = 0; //判断用户中心策略 $fan['salt'] = util_random(8); if (empty($fan['subscribetime'])) { $fan['subscribetime'] = TIMESTAMP; } $m->table('__MMB_MAPPING_FANS__')->data($fan)->add(); } else { if (empty($fan['subscribetime'])) { unset($fan['subscribetime']); } if (empty($fan['unsubscribetime'])) { unset($fan['unsubscribetime']); } $m->table('__MMB_MAPPING_FANS__')->data($fan)->where("`fanid`='{$fanid}'")->save(); } } }
public function create($member, $fan = null) { if (!preg_match('/^1\\d{10}$/', $member['mobile'])) { return error(-1, '你输入的手机号格式不正确'); } $condition = '`mobile`=:mobile'; $pars = array(); $pars[':mobile'] = $member['mobile']; $exist = $this->table('__MMB_MEMBERS__')->where($condition)->bind($pars)->find(); if (!empty($exist)) { return error(-2, '你输入的手机号已经注册过, 请直接登陆或者更换后重试'); } $rec = coll_elements(array('mobile', 'password'), $member, ''); $rec['salt'] = util_random(8); $rec['password'] = Utility::encodePassword($rec['password'], $rec['salt']); $condition = '`isdefault`=1'; $pars = array(); $group = $this->table('__MMB_GROUPS__')->where($condition)->bind($pars)->find(); $rec['groupid'] = $group['id']; $rec['createtime'] = TIMESTAMP; $rec['joinfrom'] = $member['from']; if (empty($rec['joinfrom'])) { $rec['joinfrom'] = ''; } $ret = $this->table('__MMB_MEMBERS__')->data($rec)->add(); if (empty($ret)) { return error(-2, '系统错误, 创建会员失败, 请稍后重试'); } $uid = $this->getLastInsID(); $this->table('__MMB_PROFILES__')->data(array('uid' => $uid))->add(); if (!empty($fan) && empty($fan['uid'])) { if ($rec['joinfrom'] == 'weixin') { $record = array(); $record['uid'] = $uid; $this->table('__MMB_MAPPING_FANS__')->data($record)->where("`fanid`='{$fan['fanid']}' OR `unionid`='{$fan['unionid']}'")->save(); } } return $uid; }
public function weixinModify() { $id = intval(I('get.id')); if (empty($id)) { $this->error('访问错误'); } $a = new Account(); $account = $a->getAccount($id, Account::ACCOUNT_WEIXIN); if (empty($account)) { $this->error('访问错误'); } if (IS_POST) { if (I('post.method') == 'generate') { $rec = array(); $rec['token'] = util_random(32); $rec['aeskey'] = util_random(43); $a->table('__PLATFORM_WEIXIN__')->data($rec)->where("`id`='{$id}'")->save(); exit(json_encode($rec)); } $rec = array(); $rec['level'] = intval(I('post.level')); if ($rec['level'] != '0') { $rec['appid'] = I('post.appid'); $rec['secret'] = I('post.secret'); if (empty($rec) || empty($rec['secret'])) { $this->error('您当前选择的公众号类型必须输入AppId和Secret'); } $access = WeiXin::getAccessToken($rec['appid'], $rec['secret']); if (is_error($access)) { $this->error('您输入的AppId和Secret经验证是无效的, 请检查. 错误详情: ' . $access['message']); } $_POST['access_token'] = $access['token']; $_POST['access_expire'] = $access['expire']; } $ret = $a->modify(Account::ACCOUNT_WEIXIN, $id); if (is_error($ret)) { $this->error($ret['message']); } $this->success('保存成功'); exit; } $this->assign('entity', $account); $this->display('weixin-form'); }
public function parse($message) { $msg = array(); if (!empty($message)) { $xml = $message; $dom = new \DOMDocument(); if ($dom->loadXML($xml)) { $xpath = new \DOMXpath($dom); $msg['from'] = $xpath->evaluate('string(//XML/FromUserId)'); $msg['to'] = $xpath->evaluate('string(//XML/AppId)'); $msg['time'] = $xpath->evaluate('string(//XML/CreateTime)'); $msg['type'] = 'unknow'; $elms = $xpath->query('//XML/*'); foreach ($elms as $elm) { if ($elm->childNodes->length == 1) { $msg['original'][strtolower($elm->nodeName)] = strval($elm->nodeValue); } } $type = $xpath->evaluate('string(//XML/MsgType)'); if ($type == 'text') { $msg['type'] = Platform::MSG_TEXT; $msg['content'] = $xpath->evaluate('string(//XML/Text/Content)'); } if ($type == 'image') { $msg['type'] = Platform::MSG_IMAGE; $id = $xpath->evaluate('string(//XML/Image/MediaId)'); $format = $xpath->evaluate('string(//XML/Image/Format)'); $mediaData = $this->client->download($id); $fname = util_random(32) . '.' . $format; file_put_contents(MB_ROOT . 'attachment/media/alipay/' . $fname, $mediaData); $msg['url'] = '/attachment/media/alipay/' . $fname; } if ($type == 'event') { //处理其他事件类型 $event = $xpath->evaluate('string(//XML/EventType)'); if ($event == 'follow') { //开始关注 $msg['type'] = Platform::MSG_SUBSCRIBE; } if ($event == 'unfollow') { //取消关注 $msg['type'] = Platform::MSG_UNSUBSCRIBE; } if ($event == 'enter') { //进入对话 $msg['type'] = Platform::MSG_ENTER; $scene = @json_decode($message['original']['actionparam'], true); if (!empty($scene)) { $msg['scene'] = $scene['sceneId']; } } if ($event == 'click') { $msg['type'] = Platform::MSG_MENU_CLICK; $params = $message['original']['actionparam']; if (!empty($params)) { $msg['params'] = $params; } } } } } $this->message = $msg; return $msg; }
/** * 上传文件保存,缩略图暂未实现 * * @param string $file 上传的$_FILE字段 * @param string $type 上传类型(将按分类保存不同子目录,image -> images) * @param string $sname 保存的文件名,如果为 auto 则自动生成文件名,否则请指定从附件目录开始的完整相对路径(包括文件名,不包括文件扩展名) * @param array $extra * @return array 返回结果数组,字段包括:success => bool 是否上传成功,path => 保存路径(从附件目录开始的完整相对路径) */ public static function upload($file, $type = 'image', $sname = 'auto') { if (empty($file)) { return error(-1, '没有上传内容'); } $type = in_array($type, array('image', 'audio')) ? $type : 'image'; $settings = array('image' => array('storage' => 'images/', 'extentions' => array('jpg', 'png'), 'limit' => 1024)); if (!array_key_exists($type, $settings)) { return error(-1, '未知的上传类型'); } $extention = pathinfo($file['name'], PATHINFO_EXTENSION); if (!in_array(strtolower($extention), $settings[$type]['extentions'])) { return error(-1, '不允许上传此类文件'); } if (!empty($settings[$type]['limit']) && $settings[$type]['limit'] * 1024 < filesize($file['tmp_name'])) { return error(-1, "上传的文件超过大小限制,请上传小于 {$settings[$type]['limit']}k 的文件"); } $path = MB_ROOT . '/attachment/'; $ret = array(); if ($sname == 'auto') { $ret['filename'] = $settings[$type]['storage'] . date('Y/m/'); File::mkdirs($path . $ret['filename']); do { $filename = util_random(30) . ".{$extention}"; } while (file_exists($path . $ret['filename'] . $filename)); $ret['filename'] .= $filename; } else { $ret['filename'] = $settings[$type]['storage'] . $sname; mkdirs(dirname($path . $ret['filename'])); } $ret['abs'] = $path . $ret['filename']; if (!File::move($file['tmp_name'], $ret['abs'])) { return error(-1, '保存上传文件失败'); } $ret['url'] = attach('attachment/' . $ret['filename']); return $ret; }