ylsunyuan技术论坛中心

 找回密码
 注册(请使用中文注册)
搜索
热搜: 活动 交友 discuz
查看: 765|回复: 0
打印 上一主题 下一主题

微信模块简例

[复制链接]

124

主题

127

帖子

619

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
619
跳转到指定楼层
楼主
发表于 2015-4-26 17:37:26 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
  1. <?php
  2. // 数据库的增加、查找,更新和删除-----------------------------------------------
  3. // 正则表达式/^报名/ 只匹配报名开头的关键字语句
  4. // preg_match_all('/^报名 (.+)/',"报名 张三",$matches); $matches[1][0]返回的是张三
  5. // 新建模块:合局设置,新建模块,模块类型(其它),需要嵌入的规则,生成,安装
  6. // 模块路径:根/public_html/source/modules

  7. //查找
  8. $content = $this->message['content'];
  9. $openid = $this->message['from'];
  10. $sql = "select * from ".tablename('register')." where openid = :openid";
  11. $array = array(':openid'=>$openid);
  12. //如果注册成功
  13. $msg = '';
  14. if($res=pdo_fetch($sql,$array)){
  15.         $msg = "你已经注册,\n注册名是:$res['name']"; //双引号里面才有用\n换行
  16. }else{
  17. //增加
  18.         preg_match_all('/^报名 (.+)/',$content,$matches);
  19.         $res = pdo_insert('regist',array('openid'=>$openid,'name'=>$matches[1][0]));
  20.         if($res)
  21.         {
  22.                 $msg = "注册成功!";
  23.         }else{
  24.                 $msg = "注册失败!";
  25.         }
  26. }
  27. return $this ->respText['$msg'];





  28. // 删除 pdo_delete(‘表名’,条件关联数组$arr,and/or 默认是and);
  29. $openid = $this->message['from'];
  30. $arr = arry('openid'=>$openid); //不加条件默认是删除所有数据
  31. $res = pdo_delete('tablename',$arr); //返回1 影响一条
  32. return $this->respText($res);  //respNews 图文

  33. //更新数据
  34. $whereArr = arry('openid'=>$openid);
  35. $dataArr = array('name'=>'李四');
  36. //对应参数 表名,更新的数据,更新的条件
  37. $res = pdo_update('register',$dataArr,$whereArr);//对应参数 表名,更新的数据,更新的条件
  38. return $this->respText($res);


  39. //replace 删除更新  根据openid 的唯一性,如果二次插入同一个openid一样的数据 将先删除后插入,影响两行记录
  40. $sql = "replace into ".tablename('register')." ('openid','name') values ('".$openid."','王五')";
  41. $res = pdo_query($sql); //返回1或者2 删除影响1 插入影响1
  42. return $this->respText($res); //




  43. //通讯录模块的开发-----------------------------------------------------
  44. //数据库表结构
  45. create table if not exists 'ims_contacts'(
  46.         'id' int(11) not null auto_increment,
  47.         'openid' varchar(40) not null comment '微信openid',
  48.         'name' varchar(40) not null comment '名字',
  49.         'phone' varchar(40) not null comment '手机号',
  50.         primary key ('id')
  51.         )engine=myisam default charset=utf8;


复制代码


回复

使用道具 举报

本版积分规则

QQ|Archiver|手机版|小黑屋|ylsunyuan技术论坛 ( 桂ICP备14005218号-1

GMT+8, 2024-5-3 13:20 , Processed in 0.058788 second(s), 23 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表