No Description

SecretCounterUtil.php 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <?php
  2. include './SecretContext.php';
  3. include './iCache.php';
  4. include '../../TopSdk.php';
  5. class SecretCounterUtil
  6. {
  7. private $topClient ;
  8. private $cacheClient = null;
  9. private $counterMap;
  10. function __construct($client)
  11. {
  12. $this->topClient = $client;
  13. $counterMap = array();
  14. }
  15. /*
  16. * 如果不走缓存模式,析构即调用API回传统计信息
  17. */
  18. function __destruct()
  19. {
  20. if($this->cacheClient == null){
  21. }
  22. }
  23. function report($session)
  24. {
  25. $request = new TopSdkFeedbackUploadRequest;
  26. }
  27. function setCacheClient($cache)
  28. {
  29. $this->cacheClient = $cache;
  30. }
  31. function incrDecrypt($delt,$session,$type)
  32. {
  33. $item = getItem($session);
  34. if($item == null){
  35. $item = new SecretCounter();
  36. putItem($session,$item);
  37. }
  38. if($type == "nick"){
  39. $item->$decryptNickNum += $delt;
  40. }else if($type == "receiver_name"){
  41. $item->$decryptReceiverNameNum += $delt ;
  42. }else if($type == "phone"){
  43. $item->$decryptPhoneNum += $delt ;
  44. }else if($type == "simple"){
  45. $item->$decryptSimpleNum += $delt ;
  46. }
  47. }
  48. function incrEncrypt($delt,$session,$type)
  49. {
  50. $item = getItem($session);
  51. if($item == null){
  52. $item = new SecretCounter();
  53. putItem($session,$item);
  54. }
  55. if($type == "nick"){
  56. $item->$encryptNickNum += $delt ;
  57. }else if($type == "receiver_name"){
  58. $item->$encryptReceiverNameNum += $delt ;
  59. }else if($type == "phone"){
  60. $item->$encryptPhoneNum += $delt ;
  61. }else if($type == "simple"){
  62. $item->$encryptSimpleNum += $delt ;
  63. }
  64. }
  65. function getItem($session)
  66. {
  67. if($this->cacheClient == null){
  68. return $counterMap[$session];
  69. }else{
  70. return $this->cacheClient->getCache('s_'.$session);
  71. }
  72. }
  73. function putItem($session,$item)
  74. {
  75. if($this->cacheClient == null){
  76. $counterMap[$session] = $item;
  77. }else{
  78. $this->cacheClient->setCache('s_'.$session,$item);
  79. }
  80. }
  81. }
  82. ?>