wsq.class.php 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: wsq.class.php 36284 2016-12-12 00:47:50Z nemohou $
  7. */
  8. if (!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class wsq {
  12. public static $WSQ_DOMAIN = 'http://wsq.discuz.com/?';
  13. public static $API_URL = 'http://wsq.discuz.com/?';
  14. public static $SETTING = array();
  15. private static function _dfsockopen($get, $post = array()) {
  16. global $_G;
  17. $return = dfsockopen(self::$API_URL.http_build_query($get), 0, $post, '', false, $_G['config']['wsqapi_ip']);
  18. return json_decode($return);
  19. }
  20. private static function _check_sign($data, $token, $signature = '') {
  21. if(isset($data['signature'])) {
  22. $signature = $data['signature'];
  23. unset($data['signature'], $data['mobile']);
  24. }
  25. $tt = $data['tt'] ? $data['tt'] : $data['timestamp'];
  26. if(!$tt || TIMESTAMP - $tt > 600) {
  27. return false;
  28. }
  29. $code = $data['code'];
  30. sort($data, SORT_STRING);
  31. $data[] = $token;
  32. $data = implode($data);
  33. $tmpstr = sha1($data);
  34. if($tmpstr === $signature && empty($code)){
  35. return true;
  36. } else {
  37. return false;
  38. }
  39. }
  40. private static function _make_sign($data, $token) {
  41. sort($data, SORT_STRING);
  42. $data[] = $token;
  43. $data = implode($data);
  44. $tmpstr = sha1($data);
  45. return $tmpstr;
  46. }
  47. private static function _convert($post) {
  48. foreach($post as $k => $v) {
  49. $post[$k] = diconv($v, CHARSET, 'UTF-8');
  50. }
  51. return $post;
  52. }
  53. private static function _setting() {
  54. global $_G;
  55. if(!self::$SETTING) {
  56. self::$SETTING = unserialize($_G['setting']['mobilewechat']);
  57. }
  58. }
  59. private static function _token() {
  60. self::_setting();
  61. return self::$SETTING['wsq_sitetoken'];
  62. }
  63. private static function _siteid() {
  64. self::_setting();
  65. return self::$SETTING['wsq_siteid'];
  66. }
  67. public static function decodeauth($auth) {
  68. global $_G;
  69. list($uid, $tt, $siteid, $clientip) = explode("\t", authcode($auth, 'DECODE', self::_token()));
  70. if($clientip) {
  71. $_G['clientip'] = $clientip;
  72. }
  73. if($uid && $siteid == self::_siteid() && $tt > TIMESTAMP) {
  74. return $uid;
  75. } else {
  76. return 0;
  77. }
  78. }
  79. public static function register($sitename, $siteurl, $sitelogo, $sitesummary, $mptype, $qrtype, $siteip, $followurl, $appid, $appsecret, $globalbanner, $setting) {
  80. global $_G;
  81. $get = array(
  82. 'c' => 'site',
  83. 'a' => 'register'
  84. );
  85. $post = array(
  86. 'sitename' => $sitename,
  87. 'siteurl' => $siteurl,
  88. 'sitelogo' => $sitelogo,
  89. 'sitesummary' => $sitesummary,
  90. 'mptype' => $mptype,
  91. 'qrtype' => $qrtype,
  92. 'siteuniqueid' => $_G['setting']['siteuniqueid'],
  93. 'siteip' => $siteip,
  94. 'followurl' => $followurl,
  95. 'appid' => $appid,
  96. 'appsecret' => $appsecret,
  97. 'globalbanner' => $globalbanner,
  98. 'setting' => serialize($setting),
  99. 'tt' => TIMESTAMP,
  100. );
  101. $post = self::_convert($post);
  102. return self::_dfsockopen($get, $post);
  103. }
  104. public static function info() {
  105. global $_G;
  106. $get = array(
  107. 'c' => 'site',
  108. 'a' => 'info',
  109. 'siteid' => self::_siteid()
  110. );
  111. return self::_dfsockopen($get);
  112. }
  113. public static function qrconnectUrl($uid, $qrreferer) {
  114. $get = array(
  115. 'c' => 'site',
  116. 'a' => 'qrconnect',
  117. 'siteid' => self::_siteid(),
  118. 'siteuid' => $uid,
  119. 'qrreferer' => $qrreferer,
  120. 'tt' => TIMESTAMP,
  121. );
  122. $get['signature'] = self::_make_sign($get, self::_token());
  123. return self::$API_URL.http_build_query($get);
  124. }
  125. public static function userregisterUrl($uid, $openid, $openidSign, $qrreferer) {
  126. $get = array(
  127. 'c' => 'site',
  128. 'a' => 'userregister',
  129. 'siteid' => self::_siteid(),
  130. 'siteuid' => $uid,
  131. 'openid' => $openid,
  132. 'openidsign' => $openidSign,
  133. 'qrreferer' => $qrreferer,
  134. 'tt' => TIMESTAMP,
  135. );
  136. $get['signature'] = self::_make_sign($get, self::_token());
  137. return self::$API_URL.http_build_query($get);
  138. }
  139. public static function wxuserregisterUrl($uid) {
  140. $get = array(
  141. 'c' => 'site',
  142. 'a' => 'wxuserregister',
  143. 'siteid' => self::_siteid(),
  144. 'siteuid' => $uid,
  145. 'tt' => TIMESTAMP,
  146. 'mobile' => 2,
  147. 'qrreferer' => $_GET['referer'],
  148. );
  149. $get['signature'] = self::_make_sign($get, self::_token());
  150. return self::$API_URL.http_build_query($get);
  151. }
  152. public static function userloginUrl($uid, $openid, $openidSign) {
  153. $get = array(
  154. 'c' => 'site',
  155. 'a' => 'userregister',
  156. 'siteid' => self::_siteid(),
  157. 'siteuid' => $uid,
  158. 'openid' => $openid,
  159. 'openidsign' => $openidSign,
  160. 'type' => 'json',
  161. 'tt' => TIMESTAMP,
  162. );
  163. $get['signature'] = self::_make_sign($get, self::_token());
  164. return self::$API_URL.http_build_query($get);
  165. }
  166. public static function userloginUrl2($uid) {
  167. $get = array(
  168. 'c' => 'site',
  169. 'a' => 'waplogin',
  170. 'siteid' => self::_siteid(),
  171. 'siteuid' => $uid,
  172. 'type' => 'json',
  173. 'tt' => TIMESTAMP,
  174. );
  175. $get['signature'] = self::_make_sign($get, self::_token());
  176. return self::$API_URL.http_build_query($get);
  177. }
  178. public static function userunbind($uid, $openid) {
  179. $get = array(
  180. 'c' => 'site',
  181. 'a' => 'userunbind',
  182. 'siteid' => self::_siteid(),
  183. 'tt' => TIMESTAMP,
  184. );
  185. $post = array(
  186. 'openid' => $openid,
  187. 'siteuid' => $uid,
  188. );
  189. $post['signature'] = self::_make_sign(array_merge($get, $post), self::_token());
  190. $return = self::_dfsockopen($get, $post);
  191. return !$return->code;
  192. }
  193. public static function edit($sitename, $siteurl, $sitelogo, $sitesummary, $mptype, $qrtype, $siteip, $followurl, $appid, $appsecret, $setting) {
  194. global $_G;
  195. $get = array(
  196. 'c' => 'site',
  197. 'a' => 'edit',
  198. 'siteid' => self::_siteid(),
  199. );
  200. $post = array(
  201. 'sitename' => $sitename,
  202. 'siteurl' => $siteurl,
  203. 'sitelogo' => $sitelogo,
  204. 'sitesummary' => $sitesummary,
  205. 'mptype' => $mptype,
  206. 'qrtype' => $qrtype,
  207. 'siteuniqueid' => $_G['setting']['siteuniqueid'],
  208. 'siteip' => $siteip,
  209. 'followurl' => $followurl,
  210. 'appid' => $appid,
  211. 'appsecret' => $appsecret,
  212. 'setting' => serialize($setting),
  213. 'tt' => TIMESTAMP,
  214. );
  215. $post = self::_convert($post);
  216. $post['signature'] = self::_make_sign(array_merge($get, $post), self::_token());
  217. return self::_dfsockopen($get, $post);
  218. }
  219. public static function recheck() {
  220. $get = array(
  221. 'c' => 'site',
  222. 'a' => 'recheck',
  223. 'siteid' => self::_siteid(),
  224. );
  225. $post = array();
  226. $post['signature'] = self::_make_sign(array_merge($get, $post), self::_token());
  227. return self::_dfsockopen($get, $post);
  228. }
  229. public static function report($action) {
  230. global $_G;
  231. $get = array(
  232. 'c' => 'report',
  233. 'a' => $action,
  234. 'siteid' => self::_siteid(),
  235. );
  236. $post = array(
  237. 'uid' => $_G['uid'],
  238. 'userip' => $_G['clientip']
  239. );
  240. $post['signature'] = self::_make_sign(array_merge($get, $post), self::_token());
  241. return self::_dfsockopen($get, $post);
  242. }
  243. public static function check($param) {
  244. if(self::_check_sign($param, self::_token())) {
  245. return $param['echostr'];
  246. }
  247. return;
  248. }
  249. public static function checksign($param) {
  250. return self::_check_sign($param, self::_token());
  251. }
  252. public static function siteinfo() {
  253. self::_setting();
  254. return array(
  255. 'siteInfo' => array(
  256. 'sName' => self::$SETTING['wsq_sitename'],
  257. 'sDesc' => self::$SETTING['wsq_sitesummary'],
  258. 'sLogo' => self::$SETTING['wsq_sitelogo'],
  259. )
  260. );
  261. }
  262. public static function stat() {
  263. self::_setting();
  264. $get = array(
  265. 'c' => 'site',
  266. 'a' => 'stat',
  267. 'siteid' => self::_siteid(),
  268. );
  269. $post = array();
  270. $post['signature'] = self::_make_sign(array_merge($get, $post), self::_token());
  271. return self::_dfsockopen($get, $post);
  272. }
  273. }
  274. ?>