WeChat (weixin) Grand turntable lottery page, database and lottery algorithm (PHP source code)

Source: Internet
Author: User
Tags chr curl http request ord pack php source code redis strlen

The WeChat lottery was used in the WeChat lottery. I saw other authors share the WeChat lottery page. I now share the turntable lottery program with the WeChat lottery page. If you need it, combine the two.

Some source code: configuration file

The code is as follows: Copy code
<? Php
Return array (
'Db _ type' => 'mysql ',
'Db _ host' => '2017. 0.0.1 ',
'Db _ name' => 'ites ',
'Db _ user' => 'root ',
'Db _ pwd' => '123 ',
'Db _ port' = & gt; 3306,
'Db _ prefix' => 'It _',
'App _ debug' => 1,
'Show _ ERROR_MSG '=> 1,
'Show _ PAGE_TRACE '=> 1,
'Data _ CACHE_TYPE '=> 'redis ',
'Redis _ host' => '2017. 0.0.1 ',
& Apsaradb for REDIS _ port' = & gt; 6379,
'Data _ CACHE_TIME '=> 3600,
'URL _ CASE_INSENSITIVE '=> true,
'Tmpl _ STRIP_SPACE '=> false,
'URL _ HTML_SUFFIX '=> '',
'Site _ name' => '123 ',
'Site _ url' => 'http: // www.111cn.net /',
'WeChat _ token' => 'Your ',
'WeChat _ APPID '=> 'Your ',
'WeChat _ appsecret' => 'Your ',
'Data _ AUTH_KEY '=> 'abcddd ',
);
?>

Commond. Php file

The code is as follows: Copy code

<? Php
Function isMobile ($ mobile ){
Return preg_match ("/^ (? : 13d | 14d | 15d | 18 [0123456789])-? D {5} (d {3} | * {3}) $/", $ mobile );
}

Function isEmail ($ email ){
Return strlen ($ email)> 6 & preg_match ("/^ [w-.] + @ [w-.] + (. w +) + $/", $ email );
}

/**
* HTTP request sending method. Currently, only CURL requests can be sent.
* @ Param string $ url request URL
* @ Param array $ params request parameters
* @ Param string $ method request method GET/POST
* @ Return array $ data response data
*/
Function http ($ url, $ params, $ method = 'get', $ header = array (), $ multi = false ){
$ Opts = array (
CURLOPT_TIMEOUT => 30,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_HTTPHEADER => $ header
);

/* Set specific parameters based on the request type */
Switch (strtoupper ($ method )){
Case 'get ':
$ Opts [CURLOPT_URL] = $ url .'? '. Http_build_query ($ params );
Break;
Case 'Post ':
// Determine whether a file is transmitted
// $ Params = $ multi? $ Params: http_build_query ($ params );
$ Opts [CURLOPT_URL] = $ url;
$ Opts [CURLOPT_POST] = 1;
$ Opts [CURLOPT_POSTFIELDS] = $ params;
Break;
Default:
Throw new Exception ('unsupported request method! ');
 }

/* Initialize and execute the curl request */
$ Ch = curl_init ();
Curl_setopt_array ($ ch, $ opts );
$ Data = curl_exec ($ ch );
$ Error = curl_error ($ ch );
Curl_close ($ ch );
If ($ error) throw new Exception ('request error: '. $ error );
Return $ data;
}

/**
* Do not escape Chinese characters and/json encoding methods
* @ Param array $ array to be encoded
* @ Return string
*/
Function jsencode ($ arr ){
$ Str = str_replace ("\/","/", Json_encode ($ arr ));
$ Search = "# \ u ([0-9a-f] +) # ie ";
 
If (strpos (strtoupper (PHP_ OS), 'win') === false ){
$ Replace = "iconv ('ucs-2be ', 'utf-8', pack ('h4', '\ 1')"; // LINUX
} Else {
$ Replace = "iconv ('ucos-2', 'utf-8', pack ('h4 ',' \ 1')"; // WINDOWS
 }
 
Return preg_replace ($ search, $ replace, $ str );
}

// Save data to a file
Function data2file ($ filename, $ arr = ''){
If (is_array ($ arr )){
$ Con = var_export ($ arr, true );
$ Con = "<? Php return $ con;?> ";
} Else {
$ Con = $ arr;
$ Con = "<? Php $ con;?> ";
 }
Write_file ($ filename, $ con );
}

/**
* System encryption method
* @ Param string $ string to be encrypted by data
* @ Param string $ key encryption key
* @ Param int $ expire expiration time in seconds
* @ Return string
* @ Author winky
*/
Function encrypt ($ data, $ key = '', $ expire = 0 ){
$ Key = md5 (empty ($ key )? C ('data _ AUTH_KEY '): $ key );
$ Data = base64_encode ($ data );
$ X = 0;
$ Len = strlen ($ data );
$ L = strlen ($ key );
$ Char = '';

For ($ I = 0; $ I <$ len; $ I ++ ){
If ($ x = $ l) $ x = 0;
$ Char. = substr ($ key, $ x, 1 );
$ X ++;
    }

$ Str = sprintf ('% 010d', $ expire? $ Expire + time (): 0 );

For ($ I = 0; $ I <$ len; $ I ++ ){
$ Str. = chr (ord (substr ($ data, $ I, 1) + (ord (substr ($ char, $ I, 1) % 256 );
    }
Return str_replace (array ('+', '/', '='), array ('-', '_', ''), base64_encode ($ str ));
}

/**
* System decryption method
* @ Param string $ string to be decrypted by data (it must be a string encrypted by the encrypt method)
* @ Param string $ key encryption key
* @ Return string
* @ Author winky
*/
Function decrypt ($ data, $ key = ''){
$ Key = md5 (empty ($ key )? C ('data _ AUTH_KEY '): $ key );
$ Data = str_replace (array ('-', '_'), array ('+', '/'), $ data );
$ Mod4 = strlen ($ data) % 4;
If ($ mod4 ){
$ Data. = substr ('====', $ mod4 );
    }
$ Data = base64_decode ($ data );
$ Expire = substr ($ data, 0, 10 );
$ Data = substr ($ data, 10 );

If ($ expire> 0 & $ expire <time ()){
Return '';
    }
$ X = 0;
$ Len = strlen ($ data );
$ L = strlen ($ key );
$ Char = $ str = '';

For ($ I = 0; $ I <$ len; $ I ++ ){
If ($ x = $ l) $ x = 0;
$ Char. = substr ($ key, $ x, 1 );
$ X ++;
    }

For ($ I = 0; $ I <$ len; $ I ++ ){
If (ord (substr ($ data, $ I, 1) <ord (substr ($ char, $ I, 1 ))){
$ Str. = chr (ord (substr ($ data, $ I, 1) + 256)-ord (substr ($ char, $ I, 1 )));
} Else {
$ Str. = chr (ord (substr ($ data, $ I, 1)-ord (substr ($ char, $ I, 1 )));
        }
    }
Return base64_decode ($ str );
}

Function getTaskStatusStr ($ status = 0, $ type = 'application', $ company = ''){
If ($ type = 'Comment') return 'has not been evaluated ';
Switch ($ status ){
Case 0:
Return $ type = 'application '? 'Submitted task requests': $ company. 'You have been invited to the task ';
Break;
Case 1:
Return $ type = 'application '? 'Application accepted by the Enterprise ': 'invitation accepted by the Enterprise ';
Break;
Case 2:
Return $ type = 'application '? 'Your application has been ignored by the Enterprise ': 'You have ignored the invitation by the Enterprise ';
Break;
Case 3:
Return $ type = 'application '? 'You have completed this task': 'This task has been completed ';
Break;
Default:
Return 'unknown status ';
Break;
 }
}


Function getArea ($ cache = true ){
$ Area = S ('s _ Area ');
If (empty ($ area) |! $ Cache ){
// The cache does not exist or parameters are read from the cache.
$ AreaModel = D ('region ');
$ Area = $ areaModel-> where ('status = 3')-> order ('sort, itemid')-> getField ('itemid, title, pid, arrparentid, child ');
// Provincial the city
Foreach ($ area as $ k => $ v ){
// If it is a top-level
If ($ v ['pid '] = 0 ){
$ Arestmr [$ v ['itemid'] ['itemid'] = $ v ['itemid'];
$ Arestmr [$ v ['itemid'] ['title'] = $ v ['title'];
$ Aresponr [$ v ['itemid'] ['pid'] = $ v ['pid'];
$ Aresponr [$ v ['itemid'] ['arrparentid'] = $ v ['arrparentid'];
$ Aresponr [$ v ['itemid'] ['child '] = $ v ['child'];
// Superior
$ Areitemr [$ v ['itemid'] ['upitemid'] = $ v ['itemid'];
$ AreaArr [$ v ['itemid'] ['uptitle'] = $ v ['title'];
   }
// Find the superior name and ID
Else {
$ Arestmr [$ v ['itemid'] ['itemid'] = $ v ['itemid'];
$ Arestmr [$ v ['itemid'] ['title'] = $ v ['title'];
$ Aresponr [$ v ['itemid'] ['pid'] = $ v ['pid'];
$ Aresponr [$ v ['itemid'] ['arrparentid'] = $ v ['arrparentid'];
$ Aresponr [$ v ['itemid'] ['child '] = $ v ['child'];
// Superior
$ Arestmr [$ v ['itemid'] ['upitemid'] = $ area [$ v ['pid'] ['itemid'];
$ AreaArr [$ v ['itemid'] ['uptitle'] = $ area [$ v ['pid'] ['title'];
   }
  }
$ Area = $ arew.r;
S ('s _ Area ', $ area );
 }
Return $ area;
}

?>

Source code download address

Http://file.111cn.net/upload/2014/3/wx.rar

 

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.