Test.class.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. <?php
  2. namespace Cas\Controller;
  3. use KIF\Cache\Memcached;
  4. use Cas\Module\Passport;
  5. use Cas\Module\WeixinApi;
  6. use Cas\Module\WeixinUser;
  7. use KIF\Core\WXController;
  8. use KIF\Core\Request;
  9. use Cas\Dao\WeixinQrcode;
  10. use Cas\Module\VogueApi;
  11. use Cas\Dao\VogueConnect;
  12. use KIF\Dao\AbstractDao;
  13. use KIF\Cookie;
  14. use Cas\Dao\WeixinChatsData;
  15. use Cas\Module\LotteryEventsTypeScratch;
  16. use Cas\Dao\WeixinUserBaseInfo;
  17. class Test extends Controller {
  18. public function doDefault() {
  19. # 抽奖
  20. // $objLotteryEventsTypeScratch = new LotteryEventsTypeScratch(1, 24);
  21. // $tmpWinData = $objLotteryEventsTypeScratch->userScratch();
  22. // lsm_ep($tmpWinData);
  23. // $checkResult = self::checkLoginStatus(false, Request::url());
  24. // if (!$checkResult->isSuccess()) {
  25. // self::redirect($checkResult->getData());
  26. // }
  27. // echo self::getNickname() .'已登录';exit;
  28. // self::echo_404();exit;
  29. # 写登录cookie
  30. $objPassport = new Passport();
  31. $tmpResult = $objPassport->writeLoginCookie(array(
  32. 'uid' => '1',
  33. 'openid' => 'oFXnzjiwQjurzw-rv_N4YRFxK5B0',
  34. 'loginType' => Passport::LOGIN_TYPE_HAS_AUTH,//base userInfo
  35. 'nickname' => '林子',
  36. 'sex' => '1',
  37. 'headimgurl'=> 'http://wx.qlogo.cn/mmopen/5SIXXLvbyUzwfpcLCvWgfctgRLzmicFUCL0QFyxL8atGWsJFcpse1Mg4ib8JbHv4QUnXrVN3bdq4JYA8TkqOsNl9oE2CibUHfIQ/0',
  38. 'expire' => time() + 70*24*60*60, //cookie有效期7天
  39. ));
  40. var_dump($tmpResult);exit;
  41. # 删除登录cookie
  42. // var_dump(Cookie::set('TM_PASSPORT_MEMBER', 0, -1));exit;
  43. // $objVogueConnect = new VogueConnect();
  44. // $t = $objVogueConnect->add(array(
  45. // 'openid' => 'osWOmsxdrjwt0Wtm-KDL0Fch98Zo',
  46. // 'connect_uid' => '533',
  47. // 'connect_uname' => '林子',
  48. // 'connect_email' => 'lsm1@gmail.com',
  49. // 'connect_mobile' => '15811111116',
  50. // ),AbstractDao::PARAM_CREATE_ACTION_ONDUPLICATE, array());
  51. // lsm_ep($t);
  52. // echo md5('wechatosWOmsxdrjwt0Wtm-KDL0Fch98Zo渠大昂。Bboy_Canal1http://wx.qlogo.cn/mmopen/PiajxSqBRaEJXxL6L1JmZHfUNFBjpd4BARNh90A23mZiaicGUPtznkfBKriaL3OU1rTicJiapbQHG0cIm6dLomcCl1bg/0og8M4uOsdzMDosPNv8R1dyNd__VQOezXcEiiBSKSxW0eoylIeCTtFeFp0E9z6KaC1KJvJQiCzMu1UJZOeat1AWpqDWjTgbFecE_ZQ2JaueBskOcsZfMKGKhXV9aCLEkk-cmFKJX_U4Eql2ilgKzyMiu-eWO_CT-5se8i-_hokHtLg8B0Lgwechatproductsecretkey');exit;
  53. // $objVogueApi = new VogueApi();
  54. // $objWeixinApi = new WeixinApi();
  55. // $qrcodeUrlResult = $objWeixinApi->createSteadyQrcode(3);
  56. // lsm_ep($qrcodeUrlResult->getData());
  57. // $r = $objWeixinApi->getUserInfo('oFXnzjqBIeyU9pRbnDifP40KSY0o');
  58. // lsm_ep($r);
  59. # 修改用户信息
  60. # 绑定
  61. // $openid = 'osWOmsxdrjwt0Wtm-KDL0Fch98Zo';
  62. // $unionid = md5($openid + 'wechat');
  63. // $r = $objVogueApi->bind(array(
  64. // 'openid' => $openid,
  65. // 'nickname' => '渠大昂。Bboy_Canal',
  66. // 'sex' => '1',
  67. // 'headimgurl' => 'http://wx.qlogo.cn/mmopen/PiajxSqBRaEJXxL6L1JmZHfUNFBjpd4BARNh90A23mZiaicGUPtznkfBKriaL3OU1rTicJiapbQHG0cIm6dLomcCl1bg/0',
  68. // 'unionid' => 'og8M4uOsdzMDosPNv8R1dyNd__VQ',
  69. // 'token' => 'OezXcEiiBSKSxW0eoylIeCTtFeFp0E9z6KaC1KJvJQiCzMu1UJZOeat1AWpqDWjTgbFecE_ZQ2JaueBskOcsZfMKGKhXV9aCLEkk-cmFKJX_U4Eql2ilgKzyMiu-eWO_CT-5se8i-_hokHtLg8B0Lg',
  70. // ));
  71. // lsm_ep($r);
  72. # 获取用户信息
  73. // $r = $objVogueApi->userInfo('4027995');
  74. // lsm_ep($r);
  75. # 发送验证码短信
  76. // $r = $objVogueApi->sendSMS('15810227564');
  77. // lsm_ep($r);
  78. # 检查验证码
  79. // $r = $objVogueApi->verifyCode(15810227564, '03632');
  80. // lsm_ep($r);
  81. // $objWeixinQrcode = new WeixinQrcode();
  82. // $a = $objWeixinQrcode->incrStatis('oEuf2t5oS6yILLEf124neknCVweM', 4);
  83. // var_dump($a);exit;
  84. // $result = self::checkLoginStatus(false, Request::schemeDomain());
  85. // lsm_ep($result);
  86. // $user = $this->getUser();
  87. // lsm_ep($user);
  88. // $objTest = new \Cas\Dao\Test();
  89. // $a = $objTest->create(array(
  90. // 'content' => 'hello world',
  91. // ));
  92. // var_dump($a);
  93. // $key = 'test';
  94. // $objMemcached = new Memcached();
  95. // $r = $objMemcached->set($key, 'hello world');
  96. // var_dump($r);
  97. // $m = $objMemcached->getResultMessage();
  98. // var_dump($m);
  99. // $a = $objMemcached->get($key);
  100. // var_dump($a);
  101. // $objWeixinApi = new WeixinApi();
  102. // $tmpResult = $objWeixinApi->mediaUpload('/export/manager/vogue/kissy/public/upload/media/2014/0817/170257_27899.mp3', 'voice');
  103. // lsm_ep($tmpResult);
  104. // $user = array();
  105. // $objPassport = new Passport();
  106. // $tmpResult = $objPassport->getLoginInfo();
  107. // if ($tmpResult->isSuccess()) {
  108. // $user = $tmpResult->getData();
  109. // }
  110. // lsm_ep($user);
  111. // $objWeixinUser = new WeixinUser();
  112. // $openid = 'lsm-b';
  113. // $info = array(
  114. // 'openid' => $openid,
  115. // 'nickname' => 'lsm-a-name',
  116. // 'sex' => 1,
  117. // );
  118. // $a = $objWeixinUser->notsubscribe($info);
  119. // lsm_ep($a);
  120. # 写登录cookie
  121. // $objPassport = new Passport();
  122. // $tmpResult = $objPassport->writeLoginCookie(array(
  123. // 'uid' => '2',
  124. // 'openid' => 'oEuf2t5oS6yILLEf124neknCVweM',
  125. // 'loginType' => Passport::LOGIN_TYPE_HAS_AUTH,//base userInfo
  126. // 'expire' => time() + 7*24*60*60, //cookie有效期7天
  127. // ));
  128. // lsm_ep($tmpResult);
  129. $this->tpl = 'test';
  130. // $this->setOutput('user', $user);
  131. // $this->setOutput('weixinShare', array(
  132. // 'title' => '标题',
  133. // 'content' => '内容',
  134. // 'imgUrl' => 'http://vogue.lishuy.com/public/upload/image/2014/0913/z.134441_22298.jpeg'
  135. // ));
  136. }
  137. public function doLogout() {
  138. # 删除登录cookie
  139. var_dump(Cookie::set('TM_PASSPORT_MEMBER', 0, -1));exit;
  140. }
  141. public function uploadMedia(){
  142. $fields['media'] = '@/export/manager/vogue/kissy/public/upload/media/2014/0817/170257_27899.mp3';
  143. $ch = curl_init('http://file.api.weixin.qq.com/cgi-bin/media/upload?type=voice&access_token=d_clnHeNrfgiS6yWy66Dy4tNOtposlCJrry-abs-MsaK1bSW8ENyXY-91Eku5o-UbARBbo4Ye7HLgH9UaNQ4fA') ;
  144. curl_setopt($ch, CURLOPT_POST, 1);
  145. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  146. curl_setopt($ch, CURLOPT_POST, 1);
  147. curl_setopt($ch, CURLOPT_POSTFIELDS,$fields);
  148. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  149. $result = curl_exec($ch) ;
  150. if (curl_errno($ch)) {
  151. return curl_error($ch);
  152. }
  153. curl_close($ch);
  154. return $result;
  155. }
  156. public function doSendTemplate() {
  157. $objWeixinApi = new WeixinApi();
  158. $openid = 'oFXnzjiwQjurzw-rv_N4YRFxK5B0';//李淑明 test
  159. $result = $objWeixinApi->sendTemplateMessage($openid);
  160. print_r($result);
  161. }
  162. public function doModifyMsgType() {
  163. $objWeixinChatsData = new WeixinChatsData();
  164. $ids = $objWeixinChatsData->findIdsBy(array('type' => array(1, 3)));
  165. $data = $objWeixinChatsData->gets($ids);
  166. foreach ($data as $info) {
  167. switch ($info['MsgType']) {
  168. case 'text':
  169. $contentType = "文本";
  170. $msgType = WeixinChatsData::MSG_TYPE_TEXT;
  171. break;
  172. case 'image':
  173. $contentType = "图片";
  174. $msgType = WeixinChatsData::MSG_TYPE_IMG;
  175. break;
  176. case 'voice':
  177. $contentType = "语音";
  178. $msgType = WeixinChatsData::MSG_TYPE_VOICE;
  179. break;
  180. case 'video':
  181. $contentType = "视频";
  182. $msgType = WeixinChatsData::MSG_TYPE_VIDEO;
  183. break;
  184. case 'location':
  185. $contentType = "地理位置";
  186. $msgType = WeixinChatsData::MSG_TYPE_LOCATION;
  187. break;
  188. case 'link':
  189. $contentType = "链接";
  190. $msgType = WeixinChatsData::MSG_TYPE_LINK;
  191. break;
  192. case 'event':
  193. $event = $info['Event'];
  194. switch ($event) {
  195. case 'subscribe':
  196. $eventKey = $info['EventKey'];
  197. if ($eventKey) {
  198. $contentType = "扫二维码";
  199. $msgType = WeixinChatsData::MSG_TYPE_QR;
  200. } else {
  201. $contentType = "订阅";
  202. $msgType = WeixinChatsData::MSG_TYPE_SUBSCRIBE;
  203. }
  204. break 2;
  205. case 'unsubscribe':
  206. $contentType = "取消订阅";
  207. $msgType = WeixinChatsData::MSG_TYPE_UNSUBSCRIBE;
  208. break 2;
  209. case 'LOCATION':
  210. $contentType = "地理位置";
  211. $msgType = WeixinChatsData::MSG_TYPE_LOCATION;
  212. break 2;
  213. case 'CLICK':
  214. $contentType = "菜单操作";
  215. $msgType = WeixinChatsData::MSG_TYPE_MENU;
  216. break 2;
  217. case 'VIEW':
  218. $contentType = "菜单操作";
  219. $msgType = WeixinChatsData::MSG_TYPE_MENU;
  220. break 2;
  221. case 'SCAN':
  222. $contentType = "扫二维码";
  223. $msgType = WeixinChatsData::MSG_TYPE_QR;
  224. break;
  225. }
  226. break;
  227. case 'custom_send_text': //后台自定义的消息
  228. $contentType = "客服消息";
  229. $msgType = WeixinChatsData::MSG_TYPE_SEND;
  230. break;
  231. default:
  232. $contentType = "不支持";
  233. $msgType = WeixinChatsData::MSG_TYPE_UNKNOW;
  234. break;
  235. }
  236. $tableInfo = array(
  237. 'id' => $info['id'],
  238. 'type' => 1,
  239. 'msgType' => $msgType,
  240. );
  241. $result = $objWeixinChatsData->modify($tableInfo);
  242. if (!$result->isSuccess()) {
  243. print_r($result->getData());exit;
  244. }
  245. }
  246. }
  247. public function doBindTest() {
  248. $objVogueApi = new VogueApi();
  249. $openid = 'osWOmsxdrjwt0Wtm-KDL0Fch98Zo';
  250. $unionid = md5($openid + 'wechat');
  251. $r = $objVogueApi->bind(array(
  252. 'openid' => $openid,
  253. 'nickname' => '渠大昂。Bboy_Canal',
  254. 'sex' => '1',
  255. 'headimgurl' => 'http://wx.qlogo.cn/mmopen/PiajxSqBRaEJXxL6L1JmZHfUNFBjpd4BARNh90A23mZiaicGUPtznkfBKriaL3OU1rTicJiapbQHG0cIm6dLomcCl1bg/0',
  256. 'unionid' => 'og8M4uOsdzMDosPNv8R1dyNd__VQ',
  257. 'token' => 'OezXcEiiBSKSxW0eoylIeCTtFeFp0E9z6KaC1KJvJQiCzMu1UJZOeat1AWpqDWjTgbFecE_ZQ2JaueBskOcsZfMKGKhXV9aCLEkk-cmFKJX_U4Eql2ilgKzyMiu-eWO_CT-5se8i-_hokHtLg8B0Lg',
  258. ));
  259. print_r($r);exit;
  260. }
  261. /**
  262. *
  263. * 导入订阅时间
  264. * @author lishumingoo@gmail.com
  265. */
  266. public function doImportSubscribeTime() {
  267. $objWeixinUserBaseInfo = new WeixinUserBaseInfo();
  268. $users = $objWeixinUserBaseInfo->findBy(null,null,null,'id,extend');
  269. foreach ($users as $tmpUser) {
  270. $uid = $tmpUser['id'];
  271. $tmpUser = unserialize($tmpUser['extend']);
  272. if (!$tmpUser['subscribe_time']) {
  273. continue;
  274. }
  275. $tableInfo = array(
  276. 'subscribe_time' => $tmpUser['subscribe_time'],
  277. );
  278. $condition = array(
  279. 'id' => $uid,
  280. );
  281. $tmpResult = $objWeixinUserBaseInfo->update($tableInfo, $condition);
  282. if (!$tmpResult) {
  283. self::echo_msg("导入失败UID:{$uid}");
  284. }
  285. self::echo_msg("导入成功");
  286. }
  287. }
  288. public function display() {
  289. $this->render();
  290. }
  291. }