TestSearch.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: stanley-king
  5. * Date: 2016/10/7
  6. * Time: 下午1:03
  7. */
  8. define('BASE_ROOT_PATH',str_replace('/test','',dirname(__FILE__)));
  9. require_once(BASE_ROOT_PATH . '/fooder.php');
  10. require_once(BASE_ROOT_PATH . '/helper/event_looper.php');
  11. require_once(BASE_ROOT_PATH . '/helper/search/processor.php');
  12. require_once(BASE_ROOT_PATH . '/helper/search/tcp_client.php');
  13. require_once(BASE_ROOT_PATH . '/helper/search/util.php');
  14. require_once(BASE_ROOT_PATH . '/helper/category_helper.php');
  15. require_once(BASE_ROOT_PATH . '/helper/search/searcher.php');
  16. require_once(BASE_ROOT_PATH . '/helper/brand_helper.php');
  17. require_once(BASE_ROOT_PATH . '/helper/algorithm.php');
  18. require_once(BASE_ROOT_PATH . '/helper/special_helper.php');
  19. define('MOBILE_SERVER',true);
  20. define('TIME_STAMP',time());
  21. class TestSearch extends PHPUnit_Framework_TestCase
  22. {
  23. public static function setUpBeforeClass()
  24. {
  25. Base::run_util();
  26. }
  27. public function testFilter()
  28. {
  29. $words = search\word_segment::filter('哈English 文化');
  30. }
  31. public function testInit()
  32. {
  33. $dict = new search\goods_dict();
  34. $dict->init();
  35. }
  36. public function testHot()
  37. {
  38. $dict = new search\category_dict();
  39. }
  40. public function testBrand()
  41. {
  42. $dict = new search\brand_dict();
  43. }
  44. public function testSearcher()
  45. {
  46. $searcher = new search\searcher();
  47. $searcher->init();
  48. for($i = 0; $i < 10; ++$i) {
  49. $result = $searcher->get_result(array('keyword' => '', 'brand_id' => 0,'hot_id' => 11,'order' => 'price', 'sort' => 'desc', 'page_no' => 1, 'page_size' => 10));
  50. $result = $searcher->get_word('茱莉');
  51. }
  52. // $result = $searcher->match_price(array('price' => 9.27,'page_no' => 1,'page_size' => 10));
  53. // $x = 100;
  54. }
  55. public function testRequest()
  56. {
  57. for($i = 0; $i < 1000; ++$i) {
  58. $result = search\search_client::instance()->get_result(array('keyword' => 'bb'));
  59. }
  60. }
  61. public function testBrandSpecia()
  62. {
  63. $brands = new brands_special();
  64. $ret = $brands->info(4);
  65. }
  66. public function testGoods()
  67. {
  68. $mod = Model('goods');
  69. $items = $mod->getGoodsOnlineList(array(), "*", '', '', false);
  70. $mod_common = Model("goods_common");
  71. $items = $mod->field("*")->limit(false)->select();
  72. }
  73. public function testUasort()
  74. {
  75. $words = [];
  76. $words[] = array("add_time" => 104,"count" => 1);
  77. $words[] = array("add_time" => 100,"count" => 1);
  78. $words[] = array("add_time" => 300,"count" => 1);
  79. $ret = uasort($words,'comp_time');
  80. foreach ($words as $key => $val) {
  81. echo $key;
  82. }
  83. }
  84. public function testHotsearch()
  85. {
  86. $x = @explode(',',C('hot_search'));//热门搜索
  87. $goodslist = Model('goods_browse')->getGuessLikeGoods(36490,10);
  88. }
  89. public function testUnion()
  90. {
  91. $a1 = array(1,3,5,7,9);
  92. $a2 = array(1,2,3,5,8,9);
  93. $result = algorithm::set_union($a1,$a2);
  94. }
  95. public function testUnionx()
  96. {
  97. $x = '满500减50 送<a href="http://192.168.0.200/shop/index.php?act=goods&op=index&goods_id=4550" title="妮维雅 冰爽透明防晒气雾 200ml 200ml" target="_blank">[赠品]</a>';
  98. $y = stripslashes($x);
  99. preg_match('#(.*?)<a href=".*?"\s+title="(.*?)".*?>.*?</a>#s',$x,$matches);
  100. $host = $matches[2];
  101. }
  102. public function testParams()
  103. {
  104. $params = array("xxx" => 1);
  105. $params = json_encode($params);
  106. $data = array('action' => 'groupbuy','params' => array('pay_sn' => 'fdfdsafdas'));
  107. $data = json_encode($data);
  108. }
  109. public function testPay()
  110. {
  111. $pri_key = BASE_DATA_PATH .'/api/alipay/key/rsa_private_key.pem';
  112. $pub_key = BASE_DATA_PATH.'/api/alipay/key/alipay_public_key.pem';
  113. $key = file_get_contents($pri_key);
  114. $pri = openssl_get_privatekey($key);
  115. $err = openssl_error_string();
  116. //
  117. $key = file_get_contents($pub_key);
  118. $pub = openssl_get_publickey($key);
  119. $err = openssl_error_string();
  120. $body = 'discount=0.00&payment_type=1&subject=%E5%AE%9E%E7%89%A9%E8%AE%A2%E5%8D%95_580507223514222365&trade_no=2016012721001004800042946454&buyer_email=13911129867&gmt_create=2016-01-27+15%3A25%3A29&notify_type=trade_status_sync&quantity=1&out_trade_no=580507223514222365&seller_id=2088121219613123&notify_time=2016-01-27+15%3A25%3A29&body=%E5%95%86%E5%93%81%E8%AF%A6%E6%83%85&trade_status=WAIT_BUYER_PAY&is_total_fee_adjust=Y&total_fee=8.00&seller_email=napheir.ao%40lrlz.com&price=8.00&buyer_id=2088202332994802&notify_id=66af3b99b765d046d2d533eaf6558fcm68&use_coupon=N';
  121. $body = 'discount=0.00&payment_type=1&subject=%E5%AE%9E%E7%89%A9%E8%AE%A2%E5%8D%95_280507226197761365&trade_no=2016012721001004800047345139&buyer_email=13911129867&gmt_create=2016-01-27+16%3A10%3A55&notify_type=trade_status_sync&quantity=1&out_trade_no=280507226197761365&seller_id=2088121219613123&notify_time=2016-01-27+16%3A10%3A55&body=%E5%95%86%E5%93%81%E8%AF%A6%E6%83%85&trade_status=WAIT_BUYER_PAY&is_total_fee_adjust=Y&total_fee=8.00&seller_email=napheir.ao%40lrlz.com&price=8.00&buyer_id=2088202332994802&notify_id=44d5cc359f27f5cb6e31fb10f480fb0m68&use_coupon=N';
  122. openssl_sign($body, $signed, $pri);
  123. $res = openssl_verify($body, $signed, $pub);
  124. $err = openssl_error_string();
  125. $s = base64_encode($signed);
  126. $s = urlencode($s);
  127. $sign='lnxpRmnHsaeUoPgtCrGm%2FtWohi3ORJk85q9Ic6X4c10q9O%2FASMXA2Z%2BzAH9%2BgPZAwsMywUA9O4HQ3ZCCrSpPhzJ8hEQ8Dc2SsMnvmeY6UqA7Zi6MZBTSeU1AuV3IV0tN4DTpnuk9ceetwQhNEwCiRo9vjrC%2B0TTHGfXb94OfJuM%3D';
  128. $signx = urldecode($sign);
  129. $signy = base64_decode($signx);
  130. $res = openssl_verify($body, $signy, $pub);
  131. $err = openssl_error_string();
  132. // openssl_encrypt()
  133. //
  134. //
  135. // $signed = base64_encode($signed);
  136. // $signed = urlencode($signed);
  137. //
  138. // $body = 'body=%E5%95%86%E5%93%81%E8%AF%A6%E6%83%85&buyer_email=bestcoolbear%40163.com&buyer_id=2088402949754402&discount=0.00&gmt_create=2015-12-31+14%3A51%3A41&gmt_payment=2015-12-31+14%3A51%3A41&is_total_fee_adjust=N&notify_id=35ceee6a4348f21bb27838770223ad0j34&notify_time=2015-12-31+14%3A51%3A41&notify_type=trade_status_sync&out_trade_no=150504888692984277&payment_type=1&price=0.01&quantity=1&seller_email=napheir.ao%40lrlz.com&seller_id=2088121219613123&subject=%E5%AE%9E%E7%89%A9%E8%AE%A2%E5%8D%95_150504888692984277&total_fee=0.01&trade_no=2015123121001004400035472261&trade_status=TRADE_SUCCESS&use_coupon=N';
  139. // $data = 'gNvKQd0GXULuvr%2F1FKjQrKVI%2BeT%2B8qz2ohSohfkzn%2Fx5ajMUdDD1zBXsxbv9%2FJZbaLq7KihhJmlb28E02S6hI9OlG7f7%2BTJ%2FTtrh8Xy2%2FYiU2KNpjtowS%2FM3io23lgfyQgIEQ0xIpyMZg4NRdaoW6thnrgQzs%2B9rY57iFgdG%2B24%3D';
  140. // openssl_sign($body, $sig, $pri);
  141. // $sig64 = base64_encode($sig);
  142. // $res = openssl_verify($body, $sig, $pub);
  143. // $err = openssl_error_string();
  144. }
  145. public static function zero_iv($ivlen) {
  146. $result = '';
  147. for ($i = 0; $i < $ivlen; ++$i) {
  148. $result .= chr(0);
  149. }
  150. return $result;
  151. }
  152. public function testEncrypt()
  153. {
  154. $plaintext = "message to be encrypted";
  155. $cipher="AES-128-CBC";
  156. $ivlen = openssl_cipher_iv_length($cipher);
  157. // $iv = openssl_random_pseudo_bytes($ivlen);
  158. $iv = self::zero_iv($ivlen);
  159. $key = '55668899';
  160. $ciphertext = openssl_encrypt($plaintext, $cipher, $key, 0, $iv);
  161. $original_plaintext = openssl_decrypt($ciphertext, $cipher, $key, 0, $iv);
  162. }
  163. public function testDecrypt()
  164. {
  165. $ciphers = openssl_get_cipher_methods();
  166. $cipher_text = 'pvmi16xnV6C3/1O8637DUKMTuNuZruETPg5TXE8rs78=';
  167. $cipher="AES-128-CBC";
  168. $ivlen = openssl_cipher_iv_length($cipher);
  169. $iv = self::zero_iv($ivlen);
  170. $key = '55668899';
  171. $plaintext = openssl_decrypt($cipher_text, $cipher, $key, 0, $iv);;
  172. }
  173. public function testSign()
  174. {
  175. //$body= 'body=order_sn=8000000000295701&buyer_email=13911129867&buyer_id=2088202332994802&discount=0.00&gmt_create=2016-10-29 20:51:36&gmt_payment=2016-10-29 20:51:37&is_total_fee_adjust=N&notify_id=0960c111697dbcdfbedad9ed94625adm6a&notify_time=2016-10-29 20:51:38&notify_type=trade_status_sync&out_trade_no=650531089488891490&payment_type=1&price=1.80&quantity=1&seller_email=napheir.ao@lrlz.com&seller_id=2088121219613123&subject=实物订单_650531089488891490&total_fee=1.80&trade_no=2016102921001004800260656982&trade_status=TRADE_SUCCESS&use_coupon=N';
  176. $body = "xxxxffff";
  177. $pri_key = BASE_DATA_PATH .'/api/alipay/key/rsa_private_key.pem';
  178. $pub_key = BASE_DATA_PATH.'/api/alipay/key/alipay_public_key.pem';
  179. $key = file_get_contents($pri_key);
  180. $pri = openssl_get_privatekey($key);
  181. openssl_sign($body, $signed, $pri);
  182. $sign = base64_encode($signed);
  183. $key = file_get_contents($pub_key);
  184. $pub = openssl_get_publickey($key);
  185. $res = openssl_verify($body, $signed, $pub);
  186. }
  187. public function testB64()
  188. {
  189. $pub_key = BASE_DATA_PATH.'/api/alipay/key/alipay_public_key.pem';
  190. $key = file_get_contents($pub_key);
  191. $pub = openssl_get_publickey($key);
  192. $err = openssl_error_string();
  193. $data = 'MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAL+I5/3VVhfpc3TmsUjuwc8mrZycavjuE4MV9Z+EXDvPy55PAYjDvKfMtRMCsJYgO4R0fyyb1OhvglyXUKLFajxOhUm/4K2hnI1E/+8zPbY0CU5Osr4C9sxWHtY66ugTx+O4W3e4CxYTfHn+C6EuiYJ2DWJig+Obphd8CPFYFzLxAgMBAAECgYA+og9zEytXIHEv/ixlNCZOjlBhkUjt5DSfPjQXGNpseLQWLbHLvm5X1Po1oECMpzevRcU8mizSYXyYuKaWw8XMJ7/CC6A8fSBdlUeLEfTfisurEnzeUsal2K/n+WAAFj+TUncnqYtEqCCT+9c4jVkfik7FNxjbcio9p27QKDzYwQJBAOlWs593knByuSFOVnIiphhKlZy+6MUxquxhP+3NlXVaTCHHbBl8xt3fLqLmrXPUHvAt39wJ8fAvLDuNUQgP2gkCQQDSIt7bZi2hmzqfXK9rqVyJ16o0Hwqa8Z6PYhodSSsf61h3+wxdEpDFxIV9JnPWBPhCxcX+d1VddyLZacXbKuupAkBpwFesID8II5Zv19cp5zYrsDHaVlOce4QhmXmlxxTDmOcEMCN38asXhzzVq4JVCn/zDnd0fDVgS6DaZJOi+bwxAkAJg2iheCvCsDtkMZcDgcRdvTTIbUtWnm+2QBO8la5tIIN90xDJOejx+yar9syxuMHgjAGdtptXwugB/cbmWDgZAkEAiRoMv6p7WKNU34kZqpvXMIhN6hUihquVFZDJ7wiBr1tCLw/kW3uhciCViM68FgLStuefTfssgr9+oHVw/o4GjA==';
  194. $pem = "-----BEGIN PUBLIC KEY-----\n" . $data . "-----END PUBLIC KEY-----\n";
  195. $x = openssl_pkey_get_private($pem);
  196. $y = openssl_error_string();
  197. }
  198. public function testLocalSign()
  199. {
  200. // $pri_key = BASE_DATA_PATH.'/api/alipay/key/rsa_private_key.pem';
  201. // $pub_key = BASE_DATA_PATH.'/api/alipay/key/rsa_public_key.pem';
  202. $body ='body=order_sn=8000000000295404&buyer_email=13911129867&buyer_id=2088202332994802&discount=0.00&gmt_create=2016-10-29 20:24:18&gmt_payment=2016-10-29 20:24:18&is_total_fee_adjust=N&notify_id=f29b67caf1da662d7210f04b3675f3am6a&notify_time=2016-10-29 23:52:32&notify_type=trade_status_sync&out_trade_no=850531087853085490&payment_type=1&price=0.76&quantity=1&seller_email=napheir.ao@lrlz.com&seller_id=2088121219613123&subject=实物订单_850531087853085490&total_fee=0.76&trade_no=2016102921001004800260616422&trade_status=TRADE_SUCCESS&use_coupon=N';
  203. $sign ='WG+9QtqYOlmxVRzTVyso2toN1wOxXz4aBUS7ZRL7nzvDCdXaZRU3I2bN8EZ2pcag8DiU6eUXI99YY0MaTjnAJgGGESzd5S1KHDSg0ZNdsZueaLhmYQNGpap7jyRxBSDNIR+tEPU5FzgDivU4uK4f5PWu0FiOd9jOfXLIkGneRxg=';
  204. $pub_key = '/Users/stanley-king/Desktop/payment/alipay/key/alipay_public_key.pem';
  205. // $pri_key = '/Users/stanley-king/.ssh/rsa_private_key.pem';
  206. // $pub_key = '/Users/stanley-king/.ssh/rsa_public_key.pem';
  207. // $pri_key = '/Users/stanley-king/work/PHPProject/rsa_private_key.pem';
  208. // $pub_key = '/Users/stanley-king/work/PHPProject/rsa_public_key.pem';
  209. // $key = file_get_contents($pri_key);
  210. // $pri = openssl_get_privatekey($key);
  211. // openssl_sign($body, $signed, $pri);
  212. // $sign = base64_encode($signed);
  213. $key = file_get_contents($pub_key);
  214. $pub = openssl_get_publickey($key);
  215. $signed = base64_decode($sign);
  216. $res = openssl_verify($body, $signed, $pub);
  217. }
  218. public function testCmbpay()
  219. {
  220. $x = 'BranchID=0021&CoNo=006438&BillNo=5320089577&Amount=2.05&Date=20161030&ExpireTimeSpan=30&MerchantUrl=http%3A%2F%2F121.43.114.153%2Fmobile%2Fcmbpay_notify.php&MerchantPara=pay_sn%3A610531141658503490%7Corder_sn%3A8000000000298701%7Cmember_id%3A36490&MerchantCode=%7C4xKshccAHleC65HWnU828KX1n5MtZAcd1Ma4XfVTwPibT3QJLqgRwZhxSclZyyV8WE%2Fkv8jT01eYd1y%2Aed6SsJHw2BuxSoIqGeXL4b0HMTqYaZ%2AcGEyJ4n8nVYW7vDn%2AM%2FvnDRoCuahqmft0i2suJlgZP07w36WzDPmN9SKRd60%2A4HCG2GdSy0gJ1f8tcW9C7qW6ltC7XzWlZ9yJnuKeDSJ4JHzSy24invATyz8qOuehypiWCCRLYouNCJorAqFETHZgB5kfEEJzH%2AODIf24Fywe%2Amuib96thBMGwJ1A%2AuLl4FqlchHx6QYCUyxxRNcmnF7YPkfcQs43g4ekaiHKudxmAZ%2AwJMKxPRen3g9TUyXvqSW%2FpxyPELKlKJQYUGodBn6kZN0yQ7Pw%7C4fd51f4fe55b76e5e17538d7969b2fdd8f0b8e67&MerchantRetUrl=http%3A%2F%2F121.43.114.153%2Fmobile%2Findex.php&MerchantRetPara=act%3Dpay_return%26op%3Dcmbpay%26pay_sn%3D610531141658503490%26order_sn%3D8000000000298701%26member_id%3D36490';
  221. $y = urldecode($x);
  222. }
  223. public function testPubkey()
  224. {
  225. $file = fopen('/Users/stanley-king/work/PHPProject/public.key','r');
  226. $data = fread($file,1024);
  227. fclose($file);
  228. $base64 = base64_encode($data);
  229. }
  230. public function testPublicKey()
  231. {
  232. $CMPPAY_ONLINE = true;
  233. if($CMPPAY_ONLINE == true) {
  234. $pub_key = 'MIGJAoGBALKsktbh7j9O9pM0p7qnxxImgODqxjpiT7Xl2bvZCywJtwsNI6CchqAagOYGJjG0NZsnjFunTw5YM9TD5KxsUOILAL6IaNMH/fWREhVjkUDJ4CYtLWlKozElvXRp1iZxf66yHHhN4t7TE5S9NWpEBSn37TEfFLU99Go1WReI1XN1AgMBAAE=';
  235. } else {
  236. $pub_key = 'MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALuUIwMGhvbpCwYzKCMzvSMQiLAAj5y74cN09N1TXVONPWhvLWkuzEPSd1ogPJLWiVyEG7gEIBT3zTlCV+NMou0CAwEAAQ==';
  237. }
  238. $pk = chunk_split($pub_key, 64, "\n");
  239. $pk = "-----BEGIN PUBLIC KEY-----\n{$pk}-----END PUBLIC KEY-----\n";
  240. $pkid = openssl_pkey_get_public($pub_key);
  241. }
  242. public function testNull()
  243. {
  244. $x = 'a:1:{s:4:"item";a:6:{s:25:"s61_05308797997352196.png";a:3:{s:5:"image";s:25:"s61_05308797997352196.png";s:4:"type";s:7:"special";s:4:"data";s:2:"53";}s:25:"s61_05308798368461066.png";a:3:{s:5:"image";s:25:"s61_05308798368461066.png";s:4:"type";s:7:"special";s:4:"data";s:2:"49";}s:25:"s61_05308798643188523.png";a:3:{s:5:"image";s:25:"s61_05308798643188523.png";s:4:"type";s:7:"special";s:4:"data";s:2:"50";}s:25:"s61_05308798882646585.png";a:3:{s:5:"image";s:25:"s61_05308798882646585.png";s:4:"type";s:7:"special";s:4:"data";s:2:"51";}s:25:"s61_05308799439510460.png";a:3:{s:5:"image";s:25:"s61_05308799439510460.png";s:4:"type";s:7:"special";s:4:"data";s:2:"46";}s:25:"s61_05308799642656955.png";a:3:{s:5:"image";s:25:"s61_05308799642656955.png";s:4:"type";s:7:"special";s:4:"data";s:2:"47";}}}';
  245. $y = unserialize($x);
  246. }
  247. public function testDefine()
  248. {
  249. $i = 0;
  250. while ( $i < 5) {
  251. sleep(1);
  252. echo "{i} " . TIME_STAMP . "\n";
  253. ++$i;
  254. }
  255. }
  256. public function testNotin()
  257. {
  258. $x = array(1,3,4,9,8,5);
  259. $y = array(3,2,3,4,9,8);
  260. $z = algorithm::not_in($x,$y);
  261. }
  262. public function testPasswd()
  263. {
  264. $x = md5('panda@qaz@makeup');
  265. $y = md5('xmmz@20161104');
  266. }
  267. public function testTime()
  268. {
  269. list($usec, $sec) = explode(" ", microtime());
  270. $t = time();
  271. $x = intval(microtime(true) * 10000);
  272. $y = intval(microtime(true) * 10000);
  273. $k = $y - $x;
  274. $z = microtime(true);
  275. $w = microtime(true);
  276. echo ($y - $x);
  277. }
  278. }