https://github.com/bcit-ci/CodeIgniter/archive/3.1.0.zip
½âѹµ½¸ùĿ¼
2.´´½¨Controllerapplication/controller/User.php
Ä¿±êURL
http://financeapi.applinzi.com/index.php/user/login/
3.½ÓÊÕopenid²ÎÊýʹÓÃinputÀ࣬¸ü°²È«
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class User extends CI_Controller {
- public function login() {
- echo $this->input->post('openid');
- }
- }
4.½¨±í
- CREATE TABLE `user` (
- `id` int(11) NOT NULL AUTO_INCREMENT,
- `username` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
- `openid` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
- `accessToken` char(32) COLLATE utf8_unicode_ci DEFAULT NULL,
- PRIMARY KEY (`id`),
- UNIQUE KEY `username` (`username`),
- ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
5.²éѯÊý¾Ý¿â£¬¸ÃÓû§ÊÇ·ñ´æÔÚ¡£Èç´æÔÚ£¬Ôò·µ»ØÓû§ÐÅÏ¢¹©Ð¡³ÌÐò±¾µØstorage±£´æ£»Èô²»´æÔÚ£¬ÔòÏÈн¨Ò»¸öÓû§¡£
¼ÓÔØÊý¾Ý¿âÀࣺ
autoload.php µÚ61ÐÐ
- $autoload['libraries'] = array('database');
ÅäÖÃÊý¾Ý¿âÁ¬½Ó
database.php
- $db['default'] = array(
- 'dsn' => '',
- 'hostname' => 'localhost',
- 'username' => '',
- 'password' => '',
- 'database' => '',
- );
Êý¾Ý¿âÀࣺhttp://codeigniter.org.cn/user_guide/database/results.html#id5
²éѯ´úÂ룺
- public function login() {
- header("Content-type: application/json");
- // È¡³ö²ÎÊý
- $openid = $this->input->post('openid');
- // ²éѯÊý¾Ý¿â
- $query = $this->db->query("select * from user where openid = '" . $openid . "'");
- // ·µ»ØÐÐÊý
- if ($query->num_rows() > 0) {
- // È¡³ö¸ÃÓû§
- $user = $query->first_row();
- // Êä³öÓû§µÄÐÅÏ¢
- echo json_encode($user);
- return;
- }
- }
н¨´úÂ룺
- // ×¢²áÓû§
- $user = array(
- 'username' => $openid,
- 'openid' => $openid,
- 'accessToken' => md5(time().'mysalt')
- );
- $this->db->insert('user', $user);
- echo json_encode($user);
- return;
¡¡
1.±¾Õ¾×ñÑÐÐÒµ¹æ·¶£¬ÈκÎתÔصĸå¼þ¶¼»áÃ÷È·±ê×¢×÷ÕߺÍÀ´Ô´£»2.±¾Õ¾µÄÔ´´ÎÄÕ£¬ÇëתÔØʱÎñ±Ø×¢Ã÷ÎÄÕÂ×÷ÕߺÍÀ´Ô´£¬²»×ðÖØÔ´´µÄÐÐΪÎÒÃǽ«×·¾¿ÔðÈΣ»3.×÷ÕßͶ¸å¿ÉÄÜ»á¾ÎÒÃDZà¼Ð޸Ļò²¹³ä¡£
-
΢ÐÅС³ÌÐò ÂÖ²¥Í¼ swiperͼƬ×é¼þ
2016-11-23 09:49
-
΢ÐÅС³ÌÐò ¿ª·¢ ΢ÐÅ¿ª·¢Õß¹¤¾ß ¿ì½Ý¼ü
2016-11-23 09:49
-
΢ÐÅС³ÌÐò Ò³ÃæÌøת ´«µÝ²ÎÊý
2016-11-23 09:49
-
΢ÐÅС³ÌÐò ÈçºÎ»ñȡʱ¼ä
2016-11-23 09:49