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

Source: Internet
Author: User
Currently, the most popular game is the lucky draw activity. I can see that the webmaster has sorted out the source code for this lucky draw. I will share it with you later. Currently, the most popular game is the lucky draw activity. I can see that the webmaster has sorted out the source code for this lucky draw. I will share it with you later.

Script ec (2); script

The lottery was used during the process. Other authors read the lottery and shared the page. I now share the turntable lottery program and the lottery page. If you need it, combine the two.

Some source code: Configuration File

The Code is as follows:
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:

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 =" ";
} Else {
$ Con = $ arr;
$ 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 )) $ 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

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

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.