init: from backup

main
Lei OT 2 years ago
commit b46dd7294f

8
.gitignore vendored

@ -0,0 +1,8 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
.git
.svn
.vscode
web.config

@ -0,0 +1 @@
JLsMVSE3xSgQbbcP

11
api/.gitignore vendored

@ -0,0 +1,11 @@
.DS_Store
application/cache/*
!application/cache/index.html
!application/cache/.htaccess
application/logs/*
!application/logs/index.html
!application/logs/.htaccess
bokun-product/*

@ -0,0 +1 @@
Deny from all

@ -0,0 +1 @@
Deny from all

@ -0,0 +1,10 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

@ -0,0 +1,135 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| AUTO-LOADER
| -------------------------------------------------------------------
| This file specifies which systems should be loaded by default.
|
| In order to keep the framework as light-weight as possible only the
| absolute minimal resources are loaded by default. For example,
| the database is not connected to automatically since no assumption
| is made regarding whether you intend to use it. This file lets
| you globally define which systems you would like loaded with every
| request.
|
| -------------------------------------------------------------------
| Instructions
| -------------------------------------------------------------------
|
| These are the things you can load automatically:
|
| 1. Packages
| 2. Libraries
| 3. Drivers
| 4. Helper files
| 5. Custom config files
| 6. Language files
| 7. Models
|
*/
/*
| -------------------------------------------------------------------
| Auto-load Packages
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['packages'] = array(APPPATH.'third_party', '/usr/local/shared');
|
*/
$autoload['packages'] = array();
/*
| -------------------------------------------------------------------
| Auto-load Libraries
| -------------------------------------------------------------------
| These are the classes located in system/libraries/ or your
| application/libraries/ directory, with the addition of the
| 'database' library, which is somewhat of a special case.
|
| Prototype:
|
| $autoload['libraries'] = array('database', 'email', 'session');
|
| You can also supply an alternative library name to be assigned
| in the controller:
|
| $autoload['libraries'] = array('user_agent' => 'ua');
*/
$autoload['libraries'] = array();
/*
| -------------------------------------------------------------------
| Auto-load Drivers
| -------------------------------------------------------------------
| These classes are located in system/libraries/ or in your
| application/libraries/ directory, but are also placed inside their
| own subdirectory and they extend the CI_Driver_Library class. They
| offer multiple interchangeable driver options.
|
| Prototype:
|
| $autoload['drivers'] = array('cache');
|
| You can also supply an alternative property name to be assigned in
| the controller:
|
| $autoload['drivers'] = array('cache' => 'cch');
|
*/
$autoload['drivers'] = array();
/*
| -------------------------------------------------------------------
| Auto-load Helper Files
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['helper'] = array('url', 'file');
*/
$autoload['helper'] = array();
/*
| -------------------------------------------------------------------
| Auto-load Config files
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['config'] = array('config1', 'config2');
|
| NOTE: This item is intended for use ONLY if you have created custom
| config files. Otherwise, leave it blank.
|
*/
$autoload['config'] = array();
/*
| -------------------------------------------------------------------
| Auto-load Language files
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['language'] = array('lang1', 'lang2');
|
| NOTE: Do not include the "_lang" part of your file. For example
| "codeigniter_lang.php" would be referenced as array('codeigniter');
|
*/
$autoload['language'] = array();
/*
| -------------------------------------------------------------------
| Auto-load Models
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['model'] = array('first_model', 'second_model');
|
| You can also supply an alternative model name to be assigned
| in the controller:
|
| $autoload['model'] = array('first_model' => 'first');
*/
$autoload['model'] = array();

@ -0,0 +1,523 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
|
| WARNING: You MUST set this value!
|
| If it is not set, then CodeIgniter will try guess the protocol and path
| your installation, but due to security concerns the hostname will be set
| to $_SERVER['SERVER_ADDR'] if available, or localhost otherwise.
| The auto-detection mechanism exists only for convenience during
| development and MUST NOT be used in production!
|
| If you need to allow multiple domains, remember that this file is still
| a PHP script and you can easily do that on your own.
|
*/
$config['base_url'] = '';
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = 'index.php';
/*
|--------------------------------------------------------------------------
| URI PROTOCOL
|--------------------------------------------------------------------------
|
| This item determines which server global should be used to retrieve the
| URI string. The default setting of 'REQUEST_URI' works for most servers.
| If your links do not seem to work, try one of the other delicious flavors:
|
| 'REQUEST_URI' Uses $_SERVER['REQUEST_URI']
| 'QUERY_STRING' Uses $_SERVER['QUERY_STRING']
| 'PATH_INFO' Uses $_SERVER['PATH_INFO']
|
| WARNING: If you set this to 'PATH_INFO', URIs will always be URL-decoded!
*/
$config['uri_protocol'] = 'REQUEST_URI';
/*
|--------------------------------------------------------------------------
| URL suffix
|--------------------------------------------------------------------------
|
| This option allows you to add a suffix to all URLs generated by CodeIgniter.
| For more information please see the user guide:
|
| https://codeigniter.com/user_guide/general/urls.html
*/
$config['url_suffix'] = '';
/*
|--------------------------------------------------------------------------
| Default Language
|--------------------------------------------------------------------------
|
| This determines which set of language files should be used. Make sure
| there is an available translation if you intend to use something other
| than english.
|
*/
$config['language'] = 'english';
/*
|--------------------------------------------------------------------------
| Default Character Set
|--------------------------------------------------------------------------
|
| This determines which character set is used by default in various methods
| that require a character set to be provided.
|
| See http://php.net/htmlspecialchars for a list of supported charsets.
|
*/
$config['charset'] = 'UTF-8';
/*
|--------------------------------------------------------------------------
| Enable/Disable System Hooks
|--------------------------------------------------------------------------
|
| If you would like to use the 'hooks' feature you must enable it by
| setting this variable to TRUE (boolean). See the user guide for details.
|
*/
$config['enable_hooks'] = TRUE;
/*
|--------------------------------------------------------------------------
| Class Extension Prefix
|--------------------------------------------------------------------------
|
| This item allows you to set the filename/classname prefix when extending
| native libraries. For more information please see the user guide:
|
| https://codeigniter.com/user_guide/general/core_classes.html
| https://codeigniter.com/user_guide/general/creating_libraries.html
|
*/
$config['subclass_prefix'] = 'MY_';
/*
|--------------------------------------------------------------------------
| Composer auto-loading
|--------------------------------------------------------------------------
|
| Enabling this setting will tell CodeIgniter to look for a Composer
| package auto-loader script in application/vendor/autoload.php.
|
| $config['composer_autoload'] = TRUE;
|
| Or if you have your vendor/ directory located somewhere else, you
| can opt to set a specific path as well:
|
| $config['composer_autoload'] = '/path/to/vendor/autoload.php';
|
| For more information about Composer, please visit http://getcomposer.org/
|
| Note: This will NOT disable or override the CodeIgniter-specific
| autoloading (application/config/autoload.php)
*/
$config['composer_autoload'] = FALSE;
/*
|--------------------------------------------------------------------------
| Allowed URL Characters
|--------------------------------------------------------------------------
|
| This lets you specify which characters are permitted within your URLs.
| When someone tries to submit a URL with disallowed characters they will
| get a warning message.
|
| As a security measure you are STRONGLY encouraged to restrict URLs to
| as few characters as possible. By default only these are allowed: a-z 0-9~%.:_-
|
| Leave blank to allow all characters -- but only if you are insane.
|
| The configured value is actually a regular expression character group
| and it will be executed as: ! preg_match('/^[<permitted_uri_chars>]+$/i
|
| DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!!
|
*/
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
/*
|--------------------------------------------------------------------------
| Enable Query Strings
|--------------------------------------------------------------------------
|
| By default CodeIgniter uses search-engine friendly segment based URLs:
| example.com/who/what/where/
|
| You can optionally enable standard query string based URLs:
| example.com?who=me&what=something&where=here
|
| Options are: TRUE or FALSE (boolean)
|
| The other items let you set the query string 'words' that will
| invoke your controllers and its functions:
| example.com/index.php?c=controller&m=function
|
| Please note that some of the helpers won't work as expected when
| this feature is enabled, since CodeIgniter is designed primarily to
| use segment based URLs.
|
*/
$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd';
/*
|--------------------------------------------------------------------------
| Allow $_GET array
|--------------------------------------------------------------------------
|
| By default CodeIgniter enables access to the $_GET array. If for some
| reason you would like to disable it, set 'allow_get_array' to FALSE.
|
| WARNING: This feature is DEPRECATED and currently available only
| for backwards compatibility purposes!
|
*/
$config['allow_get_array'] = TRUE;
/*
|--------------------------------------------------------------------------
| Error Logging Threshold
|--------------------------------------------------------------------------
|
| You can enable error logging by setting a threshold over zero. The
| threshold determines what gets logged. Threshold options are:
|
| 0 = Disables logging, Error logging TURNED OFF
| 1 = Error Messages (including PHP errors)
| 2 = Debug Messages
| 3 = Informational Messages
| 4 = All Messages
|
| You can also pass an array with threshold levels to show individual error types
|
| array(2) = Debug Messages, without Error Messages
|
| For a live site you'll usually only enable Errors (1) to be logged otherwise
| your log files will fill up very fast.
|
*/
$config['log_threshold'] = 2;
/*
|--------------------------------------------------------------------------
| Error Logging Directory Path
|--------------------------------------------------------------------------
|
| Leave this BLANK unless you would like to set something other than the default
| application/logs/ directory. Use a full server path with trailing slash.
|
*/
$config['log_path'] = '';
/*
|--------------------------------------------------------------------------
| Log File Extension
|--------------------------------------------------------------------------
|
| The default filename extension for log files. The default 'php' allows for
| protecting the log files via basic scripting, when they are to be stored
| under a publicly accessible directory.
|
| Note: Leaving it blank will default to 'php'.
|
*/
$config['log_file_extension'] = '';
/*
|--------------------------------------------------------------------------
| Log File Permissions
|--------------------------------------------------------------------------
|
| The file system permissions to be applied on newly created log files.
|
| IMPORTANT: This MUST be an integer (no quotes) and you MUST use octal
| integer notation (i.e. 0700, 0644, etc.)
*/
$config['log_file_permissions'] = 0644;
/*
|--------------------------------------------------------------------------
| Date Format for Logs
|--------------------------------------------------------------------------
|
| Each item that is logged has an associated date. You can use PHP date
| codes to set your own date formatting
|
*/
$config['log_date_format'] = 'Y-m-d H:i:s';
/*
|--------------------------------------------------------------------------
| Error Views Directory Path
|--------------------------------------------------------------------------
|
| Leave this BLANK unless you would like to set something other than the default
| application/views/errors/ directory. Use a full server path with trailing slash.
|
*/
$config['error_views_path'] = '';
/*
|--------------------------------------------------------------------------
| Cache Directory Path
|--------------------------------------------------------------------------
|
| Leave this BLANK unless you would like to set something other than the default
| application/cache/ directory. Use a full server path with trailing slash.
|
*/
$config['cache_path'] = '';
/*
|--------------------------------------------------------------------------
| Cache Include Query String
|--------------------------------------------------------------------------
|
| Whether to take the URL query string into consideration when generating
| output cache files. Valid options are:
|
| FALSE = Disabled
| TRUE = Enabled, take all query parameters into account.
| Please be aware that this may result in numerous cache
| files generated for the same page over and over again.
| array('q') = Enabled, but only take into account the specified list
| of query parameters.
|
*/
$config['cache_query_string'] = FALSE;
/*
|--------------------------------------------------------------------------
| Encryption Key
|--------------------------------------------------------------------------
|
| If you use the Encryption class, you must set an encryption key.
| See the user guide for more info.
|
| https://codeigniter.com/user_guide/libraries/encryption.html
|
*/
$config['encryption_key'] = '';
/*
|--------------------------------------------------------------------------
| Session Variables
|--------------------------------------------------------------------------
|
| 'sess_driver'
|
| The storage driver to use: files, database, redis, memcached
|
| 'sess_cookie_name'
|
| The session cookie name, must contain only [0-9a-z_-] characters
|
| 'sess_expiration'
|
| The number of SECONDS you want the session to last.
| Setting to 0 (zero) means expire when the browser is closed.
|
| 'sess_save_path'
|
| The location to save sessions to, driver dependent.
|
| For the 'files' driver, it's a path to a writable directory.
| WARNING: Only absolute paths are supported!
|
| For the 'database' driver, it's a table name.
| Please read up the manual for the format with other session drivers.
|
| IMPORTANT: You are REQUIRED to set a valid save path!
|
| 'sess_match_ip'
|
| Whether to match the user's IP address when reading the session data.
|
| WARNING: If you're using the database driver, don't forget to update
| your session table's PRIMARY KEY when changing this setting.
|
| 'sess_time_to_update'
|
| How many seconds between CI regenerating the session ID.
|
| 'sess_regenerate_destroy'
|
| Whether to destroy session data associated with the old session ID
| when auto-regenerating the session ID. When set to FALSE, the data
| will be later deleted by the garbage collector.
|
| Other session cookie settings are shared with the rest of the application,
| except for 'cookie_prefix' and 'cookie_httponly', which are ignored here.
|
*/
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
/*
|--------------------------------------------------------------------------
| Cookie Related Variables
|--------------------------------------------------------------------------
|
| 'cookie_prefix' = Set a cookie name prefix if you need to avoid collisions
| 'cookie_domain' = Set to .your-domain.com for site-wide cookies
| 'cookie_path' = Typically will be a forward slash
| 'cookie_secure' = Cookie will only be set if a secure HTTPS connection exists.
| 'cookie_httponly' = Cookie will only be accessible via HTTP(S) (no javascript)
|
| Note: These settings (with the exception of 'cookie_prefix' and
| 'cookie_httponly') will also affect sessions.
|
*/
$config['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;
/*
|--------------------------------------------------------------------------
| Standardize newlines
|--------------------------------------------------------------------------
|
| Determines whether to standardize newline characters in input data,
| meaning to replace \r\n, \r, \n occurrences with the PHP_EOL value.
|
| WARNING: This feature is DEPRECATED and currently available only
| for backwards compatibility purposes!
|
*/
$config['standardize_newlines'] = FALSE;
/*
|--------------------------------------------------------------------------
| Global XSS Filtering
|--------------------------------------------------------------------------
|
| Determines whether the XSS filter is always active when GET, POST or
| COOKIE data is encountered
|
| WARNING: This feature is DEPRECATED and currently available only
| for backwards compatibility purposes!
|
*/
$config['global_xss_filtering'] = FALSE;
/*
|--------------------------------------------------------------------------
| Cross Site Request Forgery
|--------------------------------------------------------------------------
| Enables a CSRF cookie token to be set. When set to TRUE, token will be
| checked on a submitted form. If you are accepting user data, it is strongly
| recommended CSRF protection be enabled.
|
| 'csrf_token_name' = The token name
| 'csrf_cookie_name' = The cookie name
| 'csrf_expire' = The number in seconds the token should expire.
| 'csrf_regenerate' = Regenerate token on every submission
| 'csrf_exclude_uris' = Array of URIs which ignore CSRF checks
*/
$config['csrf_protection'] = FALSE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
$config['csrf_regenerate'] = TRUE;
$config['csrf_exclude_uris'] = array();
/*
|--------------------------------------------------------------------------
| Output Compression
|--------------------------------------------------------------------------
|
| Enables Gzip output compression for faster page loads. When enabled,
| the output class will test whether your server supports Gzip.
| Even if it does, however, not all browsers support compression
| so enable only if you are reasonably sure your visitors can handle it.
|
| Only used if zlib.output_compression is turned off in your php.ini.
| Please do not use it together with httpd-level output compression.
|
| VERY IMPORTANT: If you are getting a blank page when compression is enabled it
| means you are prematurely outputting something to your browser. It could
| even be a line of whitespace at the end of one of your scripts. For
| compression to work, nothing can be sent before the output buffer is called
| by the output class. Do not 'echo' any values with compression enabled.
|
*/
$config['compress_output'] = FALSE;
/*
|--------------------------------------------------------------------------
| Master Time Reference
|--------------------------------------------------------------------------
|
| Options are 'local' or any PHP supported timezone. This preference tells
| the system whether to use your server's local time as the master 'now'
| reference, or convert it to the configured one timezone. See the 'date
| helper' page of the user guide for information regarding date handling.
|
*/
$config['time_reference'] = 'local';
/*
|--------------------------------------------------------------------------
| Rewrite PHP Short Tags
|--------------------------------------------------------------------------
|
| If your PHP installation does not have short tag support enabled CI
| can rewrite the tags on-the-fly, enabling you to utilize that syntax
| in your view files. Options are TRUE or FALSE (boolean)
|
| Note: You need to have eval() enabled for this to work.
|
*/
$config['rewrite_short_tags'] = FALSE;
/*
|--------------------------------------------------------------------------
| Reverse Proxy IPs
|--------------------------------------------------------------------------
|
| If your server is behind a reverse proxy, you must whitelist the proxy
| IP addresses from which CodeIgniter should trust headers such as
| HTTP_X_FORWARDED_FOR and HTTP_CLIENT_IP in order to properly identify
| the visitor's IP address.
|
| You can use both an array or a comma-separated list of proxy addresses,
| as well as specifying whole subnets. Here are a few examples:
|
| Comma-separated: '10.0.1.200,192.168.5.0/24'
| Array: array('10.0.1.200', '192.168.5.0/24')
*/
$config['proxy_ips'] = '';

@ -0,0 +1,116 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
|--------------------------------------------------------------------------
| Display Debug backtrace
|--------------------------------------------------------------------------
|
| If set to TRUE, a backtrace will be displayed along with php errors. If
| error_reporting is disabled, the backtrace will not display, regardless
| of this setting
|
*/
defined('SHOW_DEBUG_BACKTRACE') OR define('SHOW_DEBUG_BACKTRACE', TRUE);
/*
|--------------------------------------------------------------------------
| File and Directory Modes
|--------------------------------------------------------------------------
|
| These prefs are used when checking and setting modes when working
| with the file system. The defaults are fine on servers with proper
| security, but you may wish (or even need) to change the values in
| certain environments (Apache running a separate process for each
| user, PHP under CGI with Apache suEXEC, etc.). Octal values should
| always be used to set the mode correctly.
|
*/
defined('FILE_READ_MODE') OR define('FILE_READ_MODE', 0644);
defined('FILE_WRITE_MODE') OR define('FILE_WRITE_MODE', 0666);
defined('DIR_READ_MODE') OR define('DIR_READ_MODE', 0755);
defined('DIR_WRITE_MODE') OR define('DIR_WRITE_MODE', 0755);
/*
|--------------------------------------------------------------------------
| File Stream Modes
|--------------------------------------------------------------------------
|
| These modes are used when working with fopen()/popen()
|
*/
defined('FOPEN_READ') OR define('FOPEN_READ', 'rb');
defined('FOPEN_READ_WRITE') OR define('FOPEN_READ_WRITE', 'r+b');
defined('FOPEN_WRITE_CREATE_DESTRUCTIVE') OR define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb'); // truncates existing file data, use with care
defined('FOPEN_READ_WRITE_CREATE_DESTRUCTIVE') OR define('FOPEN_READ_WRITE_CREATE_DESTRUCTIVE', 'w+b'); // truncates existing file data, use with care
defined('FOPEN_WRITE_CREATE') OR define('FOPEN_WRITE_CREATE', 'ab');
defined('FOPEN_READ_WRITE_CREATE') OR define('FOPEN_READ_WRITE_CREATE', 'a+b');
defined('FOPEN_WRITE_CREATE_STRICT') OR define('FOPEN_WRITE_CREATE_STRICT', 'xb');
defined('FOPEN_READ_WRITE_CREATE_STRICT') OR define('FOPEN_READ_WRITE_CREATE_STRICT', 'x+b');
/*
|--------------------------------------------------------------------------
| Exit Status Codes
|--------------------------------------------------------------------------
|
| Used to indicate the conditions under which the script is exit()ing.
| While there is no universal standard for error codes, there are some
| broad conventions. Three such conventions are mentioned below, for
| those who wish to make use of them. The CodeIgniter defaults were
| chosen for the least overlap with these conventions, while still
| leaving room for others to be defined in future versions and user
| applications.
|
| The three main conventions used for determining exit status codes
| are as follows:
|
| Standard C/C++ Library (stdlibc):
| http://www.gnu.org/software/libc/manual/html_node/Exit-Status.html
| (This link also contains other GNU-specific conventions)
| BSD sysexits.h:
| http://www.gsp.com/cgi-bin/man.cgi?section=3&topic=sysexits
| Bash scripting:
| http://tldp.org/LDP/abs/html/exitcodes.html
|
*/
defined('EXIT_SUCCESS') OR define('EXIT_SUCCESS', 0); // no errors
defined('EXIT_ERROR') OR define('EXIT_ERROR', 1); // generic error
defined('EXIT_CONFIG') OR define('EXIT_CONFIG', 3); // configuration error
defined('EXIT_UNKNOWN_FILE') OR define('EXIT_UNKNOWN_FILE', 4); // file not found
defined('EXIT_UNKNOWN_CLASS') OR define('EXIT_UNKNOWN_CLASS', 5); // unknown class
defined('EXIT_UNKNOWN_METHOD') OR define('EXIT_UNKNOWN_METHOD', 6); // unknown class member
defined('EXIT_USER_INPUT') OR define('EXIT_USER_INPUT', 7); // invalid user input
defined('EXIT_DATABASE') OR define('EXIT_DATABASE', 8); // database error
defined('EXIT__AUTO_MIN') OR define('EXIT__AUTO_MIN', 9); // lowest automatically-assigned error code
defined('EXIT__AUTO_MAX') OR define('EXIT__AUTO_MAX', 125); // highest automatically-assigned error code
/*!
* 一些常量
*/
/** 日期格式 */
defined('DATE_FORMAT') OR define('DATE_FORMAT', 'Y-m-d');
defined('DATETIME_FORMAT') OR define('DATETIME_FORMAT', 'Y-m-d H:i:s');
defined('DB_DATE_FORMAT') OR define('DB_DATE_FORMAT', 'date'); // Y-m-d
defined('DB_DATETIME_FORMAT') OR define('DB_DATETIME_FORMAT', 'smalldatetime'); // Y-m-d H:i:s
defined('DEFAULT_DATE') OR define('DEFAULT_DATE', '2017-12-01'); // 默认的开始日期, 需要限定日期范围时
switch (ENVIRONMENT)
{
case 'development':
// defined('HOST') OR define('HOST', 'http://trippest.mycht.cn/trippest-mobile-site/build/#/');
defined('HOST') OR define('HOST', 'http://localhost:3000/#/');
break;
case 'testing':
defined('HOST') OR define('HOST', 'http://trippest.mycht.cn/trippest-mobile-site/build/#/');
break;
case 'production':
defined('HOST') OR define('HOST', 'http://trippest.mycht.cn');
break;
default:
defined('HOST') OR define('HOST', 'http://trippest.mycht.cn');
break;
}

@ -0,0 +1,7 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$active_group = 'INFO';
$query_builder = TRUE;
require 'c:/database_conn.php';

@ -0,0 +1,24 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$_doctypes = array(
'xhtml11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
'xhtml1-strict' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
'xhtml1-trans' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
'xhtml1-frame' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
'xhtml-basic11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">',
'html5' => '<!DOCTYPE html>',
'html4-strict' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
'html4-trans' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
'html4-frame' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">',
'mathml1' => '<!DOCTYPE math SYSTEM "http://www.w3.org/Math/DTD/mathml1/mathml.dtd">',
'mathml2' => '<!DOCTYPE math PUBLIC "-//W3C//DTD MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd">',
'svg10' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">',
'svg11' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">',
'svg11-basic' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Basic//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtd">',
'svg11-tiny' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Tiny//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd">',
'xhtml-math-svg-xh' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">',
'xhtml-math-svg-sh' => '<!DOCTYPE svg:svg PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">',
'xhtml-rdfa-1' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">',
'xhtml-rdfa-2' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">'
);

@ -0,0 +1,103 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| Foreign Characters
| -------------------------------------------------------------------
| This file contains an array of foreign characters for transliteration
| conversion used by the Text helper
|
*/
$foreign_characters = array(
'/ä|æ|ǽ/' => 'ae',
'/ö|œ/' => 'oe',
'/ü/' => 'ue',
'/Ä/' => 'Ae',
'/Ü/' => 'Ue',
'/Ö/' => 'Oe',
'/À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ|Α|Ά|Ả|Ạ|Ầ|Ẫ|Ẩ|Ậ|Ằ|Ắ|Ẵ|Ẳ|Ặ|А/' => 'A',
'/à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª|α|ά|ả|ạ|ầ|ấ|ẫ|ẩ|ậ|ằ|ắ|ẵ|ẳ|ặ|а/' => 'a',
'/Б/' => 'B',
'/б/' => 'b',
'/Ç|Ć|Ĉ|Ċ|Č/' => 'C',
'/ç|ć|ĉ|ċ|č/' => 'c',
'/Д/' => 'D',
'/д/' => 'd',
'/Ð|Ď|Đ|Δ/' => 'Dj',
'/ð|ď|đ|δ/' => 'dj',
'/È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě|Ε|Έ|Ẽ|Ẻ|Ẹ|Ề|Ế|Ễ|Ể|Ệ|Е|Э/' => 'E',
'/è|é|ê|ë|ē|ĕ|ė|ę|ě|έ|ε|ẽ|ẻ|ẹ|ề|ế|ễ|ể|ệ|е|э/' => 'e',
'/Ф/' => 'F',
'/ф/' => 'f',
'/Ĝ|Ğ|Ġ|Ģ|Γ|Г|Ґ/' => 'G',
'/ĝ|ğ|ġ|ģ|γ|г|ґ/' => 'g',
'/Ĥ|Ħ/' => 'H',
'/ĥ|ħ/' => 'h',
'/Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ|Η|Ή|Ί|Ι|Ϊ|Ỉ|Ị|И|Ы/' => 'I',
'/ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı|η|ή|ί|ι|ϊ|ỉ|ị|и|ы|ї/' => 'i',
'/Ĵ/' => 'J',
'/ĵ/' => 'j',
'/Ķ|Κ|К/' => 'K',
'/ķ|κ|к/' => 'k',
'/Ĺ|Ļ|Ľ|Ŀ|Ł|Λ|Л/' => 'L',
'/ĺ|ļ|ľ|ŀ|ł|λ|л/' => 'l',
'/М/' => 'M',
'/м/' => 'm',
'/Ñ|Ń|Ņ|Ň|Ν|Н/' => 'N',
'/ñ|ń|ņ|ň|ʼn|ν|н/' => 'n',
'/Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ|Ο|Ό|Ω|Ώ|Ỏ|Ọ|Ồ|Ố|Ỗ|Ổ|Ộ|Ờ|Ớ|Ỡ|Ở|Ợ|О/' => 'O',
'/ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º|ο|ό|ω|ώ|ỏ|ọ|ồ|ố|ỗ|ổ|ộ|ờ|ớ|ỡ|ở|ợ|о/' => 'o',
'/П/' => 'P',
'/п/' => 'p',
'/Ŕ|Ŗ|Ř|Ρ|Р/' => 'R',
'/ŕ|ŗ|ř|ρ|р/' => 'r',
'/Ś|Ŝ|Ş|Ș|Š|Σ|С/' => 'S',
'/ś|ŝ|ş|ș|š|ſ|σ|ς|с/' => 's',
'/Ț|Ţ|Ť|Ŧ|τ|Т/' => 'T',
'/ț|ţ|ť|ŧ|т/' => 't',
'/Þ|þ/' => 'th',
'/Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ|Ũ|Ủ|Ụ|Ừ|Ứ|Ữ|Ử|Ự|У/' => 'U',
'/ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ|υ|ύ|ϋ|ủ|ụ|ừ|ứ|ữ|ử|ự|у/' => 'u',
'/Ý|Ÿ|Ŷ|Υ|Ύ|Ϋ|Ỳ|Ỹ|Ỷ|Ỵ|Й/' => 'Y',
'/ý|ÿ|ŷ|ỳ|ỹ|ỷ|ỵ|й/' => 'y',
'/В/' => 'V',
'/в/' => 'v',
'/Ŵ/' => 'W',
'/ŵ/' => 'w',
'/Ź|Ż|Ž|Ζ|З/' => 'Z',
'/ź|ż|ž|ζ|з/' => 'z',
'/Æ|Ǽ/' => 'AE',
'/ß/' => 'ss',
'/IJ/' => 'IJ',
'/ij/' => 'ij',
'/Œ/' => 'OE',
'/ƒ/' => 'f',
'/ξ/' => 'ks',
'/π/' => 'p',
'/β/' => 'v',
'/μ/' => 'm',
'/ψ/' => 'ps',
'/Ё/' => 'Yo',
'/ё/' => 'yo',
'/Є/' => 'Ye',
'/є/' => 'ye',
'/Ї/' => 'Yi',
'/Ж/' => 'Zh',
'/ж/' => 'zh',
'/Х/' => 'Kh',
'/х/' => 'kh',
'/Ц/' => 'Ts',
'/ц/' => 'ts',
'/Ч/' => 'Ch',
'/ч/' => 'ch',
'/Ш/' => 'Sh',
'/ш/' => 'sh',
'/Щ/' => 'Shch',
'/щ/' => 'shch',
'/Ъ|ъ|Ь|ь/' => '',
'/Ю/' => 'Yu',
'/ю/' => 'yu',
'/Я/' => 'Ya',
'/я/' => 'ya'
);

@ -0,0 +1,197 @@
<?php
$config['defaultAnswer'] = [ "number"=> 0, "text"=> '请选择' ];
$config['questionToClientTemplate'] = [[
"category"=> 1,
"number"=> 1,
"text"=> '客人的工作行业 What industry does your company work? Or what industry is your role in?',
"selectedAnswer"=> $config['defaultAnswer'],
"answerChoiceList"=> [
[ "question_number"=> 1, "number"=> 10101, "text"=> '学校' ],
[ "question_number"=> 1, "number"=> 10201, "text"=> '知名企业' ],
[ "question_number"=> 1, "number"=> 10301, "text"=> '自己开公司' ],
[ "question_number"=> 1, "number"=> 10401, "text"=> '律师' ],
[ "question_number"=> 1, "number"=> 10501, "text"=> '医生' ],
[ "question_number"=> 1, "number"=> 10601, "text"=> '工程师' ],
[ "question_number"=> 1, "number"=> 10701, "text"=> '军事行业' ],
[ "question_number"=> 1, "number"=> 10801, "text"=> '房地产' ],
[ "question_number"=> 1, "number"=> 10901, "text"=> '公益机构' ],
[ "question_number"=> 1, "number"=> 11001, "text"=> '自由职业' ],
[ "question_number"=> 1, "number"=> 10001, "text"=> '其它' ]
]
],
[
"category"=> 1,
"number"=> 2,
"text"=> '客人的工作职位',
"selectedAnswer"=> $config['defaultAnswer'],
"answerChoiceList"=> [
[ "question_number"=> 2, "number"=> 10102, "text"=> '退休' ],
[ "question_number"=> 2, "number"=> 10202, "text"=> '农业&食品' ],
[ "question_number"=> 2, "number"=> 10302, "text"=> '建工类' ],
[ "question_number"=> 2, "number"=> 10402, "text"=> '艺术&通信' ],
[ "question_number"=> 2, "number"=> 10502, "text"=> '企业管理' ],
[ "question_number"=> 2, "number"=> 10602, "text"=> '教育培训' ],
[ "question_number"=> 2, "number"=> 10702, "text"=> '金融财务' ],
[ "question_number"=> 2, "number"=> 10802, "text"=> '自由职业' ],
[ "question_number"=> 2, "number"=> 10902, "text"=> '政府行政' ],
[ "question_number"=> 2, "number"=> 11002, "text"=> '健康科学' ],
[ "question_number"=> 2, "number"=> 11102, "text"=> '酒店&旅游' ],
[ "question_number"=> 2, "number"=> 11202, "text"=> '人力资源' ],
[ "question_number"=> 2, "number"=> 11302, "text"=> '信息技术' ],
[ "question_number"=> 2, "number"=> 11402, "text"=> '法律公共安全' ],
[ "question_number"=> 2, "number"=> 11502, "text"=> '制造业' ],
[ "question_number"=> 2, "number"=> 11602, "text"=> '销售服务业' ],
[ "question_number"=> 2, "number"=> 11702, "text"=> '科技工程' ],
[ "question_number"=> 2, "number"=> 11802, "text"=> '物流' ],
[ "question_number"=> 2, "number"=> 11902, "text"=> '家庭主妇' ],
[ "question_number"=> 2, "number"=> 10002, "text"=> '其它' ]
]
],
[
"category"=> 2,
"number"=> 3,
"text"=> '你选择来中国的原因是什么?',
"selectedAnswer"=> $config['defaultAnswer'],
"answerChoiceList"=> [
[ "question_number"=> 3, "number"=> 10103, "text"=> '看望在中国/亚洲工作或学习的亲朋好友' ],
[ "question_number"=> 3, "number"=> 10203, "text"=> '有家人在学中文想到中国看看' ],
[ "question_number"=> 3, "number"=> 10303, "text"=> '家人来中国/亚洲出差' ],
[ "question_number"=> 3, "number"=> 10403, "text"=> '身边有中国的朋友经常提起' ],
[ "question_number"=> 3, "number"=> 10503, "text"=> '带孩子来中国长见识' ],
[ "question_number"=> 3, "number"=> 10603, "text"=> '对中国的文化风景感兴趣' ],
[ "question_number"=> 3, "number"=> 10003, "text"=> '其它' ]
]
],
[
"category"=> 2,
"number"=> 4,
"text"=> '你什么时候开始考虑来中国旅行?',
"selectedAnswer"=> $config['defaultAnswer'],
"answerChoiceList"=> [
[ "question_number"=> 4, "number"=> 10104, "text"=> '半年前' ],
[ "question_number"=> 4, "number"=> 10204, "text"=> '一年前' ],
[ "question_number"=> 4, "number"=> 10304, "text"=> '2年前' ],
[ "question_number"=> 4, "number"=> 10004, "text"=> '其它' ]
]
],
[
"category"=> 2,
"number"=> 5,
"text"=> '你计划中国旅行最大的挑战是什么What are your biggest challenges when you planned this trip?',
"selectedAnswer"=> $config['defaultAnswer'],
"answerChoiceList"=> [
[ "question_number"=> 5, "number"=> 10105, "text"=> '协调一家人的出行时间' ],
[ "question_number"=> 5, "number"=> 10205, "text"=> '中国太大行程安排复杂,无精力计划' ],
[ "question_number"=> 5, "number"=> 10305, "text"=> '控制预算' ],
[ "question_number"=> 5, "number"=> 10405, "text"=> '孩子需求难满足' ],
[ "question_number"=> 5, "number"=> 10505, "text"=> '国际航班飞行时间太长' ],
[ "question_number"=> 5, "number"=> 10605, "text"=> '中国的安全问题' ],
[ "question_number"=> 5, "number"=> 10705, "text"=> '语言不通' ],
[ "question_number"=> 5, "number"=> 10805, "text"=> '签证麻烦' ],
[ "question_number"=> 5, "number"=> 10905, "text"=> '无法翻墙' ],
[ "question_number"=> 5, "number"=> 10005, "text"=> '其它' ]
]
],
// 使用场景如何找到CH和为何选择CH
[
"category"=> 3,
"number"=> 6,
"text"=> '你从哪里知道China Highlights',
"selectedAnswer"=> $config['defaultAnswer'],
"answerChoiceList"=> [
[ "question_number"=> 6, "number"=> 10106, "text"=> 'Google搜索' ],
[ "question_number"=> 6, "number"=> 10206, "text"=> '中国太大行程安排复杂,无精力计划' ],
[ "question_number"=> 6, "number"=> 10306, "text"=> 'TA网站 ' ],
[ "question_number"=> 6, "number"=> 10406, "text"=> '旅游博客' ],
[ "question_number"=> 6, "number"=> 10506, "text"=> '朋友推荐' ],
[ "question_number"=> 6, "number"=> 10006, "text"=> '其它' ]
]
],
[
"category"=> 3,
"number"=> 7,
"text"=> '出国旅行时通常你的旅行方式是什么Do you usually use a travel agency or travel independently? In what situation you would consider using a travel agent?',
"selectedAnswer"=> $config['defaultAnswer'],
"answerChoiceList"=> [
[ "question_number"=> 7, "number"=> 10107, "text"=> '自由行' ],
[ "question_number"=> 7, "number"=> 10207, "text"=> '旅行社跟团' ],
[ "question_number"=> 7, "number"=> 10307, "text"=> '旅行社 ' ],
[ "question_number"=> 7, "number"=> 10407, "text"=> '视目的地决定是否使用旅行社' ],
[ "question_number"=> 7, "number"=> 10007, "text"=> '其它' ]
]
],
[
"category"=> 3,
"number"=> 8,
"text"=> '你一般从哪里获取旅行资讯Where do you usually get travel information?',
"selectedAnswer"=> $config['defaultAnswer'],
"answerChoiceList"=> [
[ "question_number"=> 8, "number"=> 10108, "text"=> 'Google' ],
[ "question_number"=> 8, "number"=> 10208, "text"=> '朋友' ],
[ "question_number"=> 8, "number"=> 10308, "text"=> '社交媒体如 Facebook, Instagram, Pinterests' ],
[ "question_number"=> 8, "number"=> 10408, "text"=> '旅行杂志' ],
[ "question_number"=> 8, "number"=> 10008, "text"=> '其它' ]
]
],
[
"category"=> 3,
"number"=> 9,
"text"=> '你为何决定选择China highlightsWhy do you choose to travel with China Highlights?',
"selectedAnswer"=> $config['defaultAnswer'],
"answerChoiceList"=> [
[ "question_number"=> 9, "number"=> 10109, "text"=> '外联专业,回复速度快' ],
[ "question_number"=> 9, "number"=> 10209, "text"=> '朋友推荐CH' ],
[ "question_number"=> 9, "number"=> 10309, "text"=> 'TA好评高' ],
[ "question_number"=> 9, "number"=> 10409, "text"=> '价格合理' ],
[ "question_number"=> 9, "number"=> 10509, "text"=> '公司可信任' ],
[ "question_number"=> 9, "number"=> 10009, "text"=> '其它' ]
]
],
// 观点和机会对CH的评价与期望、重回亚洲的可能性,
[
"category"=> 4,
"number"=> 10,
"text"=> '你认为CH哪里做得比较好',
"selectedAnswer"=> $config['defaultAnswer'],
"answerChoiceList"=> [
[ "question_number"=> 10, "number"=> 10110, "text"=> '安排的体验独特' ],
[ "question_number"=> 10, "number"=> 10210, "text"=> '行程衔接好' ],
[ "question_number"=> 10, "number"=> 10310, "text"=> '导游专业' ],
[ "question_number"=> 10, "number"=> 10410, "text"=> '外联专业' ],
[ "question_number"=> 10, "number"=> 10510, "text"=> '网站专业和丰富' ],
[ "question_number"=> 10, "number"=> 10610, "text"=> 'TA好评多' ],
[ "question_number"=> 10, "number"=> 10010, "text"=> '其它' ]
]
],
[
"category"=> 4,
"number"=> 11,
"text"=> '你认为CH有哪些地方可以改进',
"selectedAnswer"=> $config['defaultAnswer'],
"answerChoiceList"=> [
[ "question_number"=> 11, "number"=> 10111, "text"=> '导游讲解的深度和趣味性' ],
[ "question_number"=> 11, "number"=> 10211, "text"=> '实际走团安排更灵活' ],
[ "question_number"=> 11, "number"=> 10311, "text"=> '车辆的舒适度和干净程度' ],
[ "question_number"=> 11, "number"=> 10411, "text"=> '酒店的选择' ],
[ "question_number"=> 11, "number"=> 10511, "text"=> '出发前来中国的常识提醒' ],
[ "question_number"=> 11, "number"=> 10011, "text"=> '其它' ]
]
],
[
"category"=> 4,
"number"=> 12,
"text"=> '未来两年你是否考虑再来亚洲期待去哪些目的地Do you consider visiting other Asian countries in the next two years? Why? What are your top three destinations?',
"selectedAnswer"=> $config['defaultAnswer'],
"answerChoiceList"=> [
[ "question_number"=> 12, "number"=> 10112, "text"=> '不考虑' ],
[ "question_number"=> 12, "number"=> 10212, "text"=> '考虑' ],
[ "question_number"=> 12, "number"=> 10012, "text"=> '其它计划' ]
]
]
];

@ -0,0 +1,182 @@
<?php
$config['defaultAnswer'] = [ "number" => 0, "text" => '请选择' ];
$config['questionToClientTemplate'] = [[
"category" => 1,
"number" => 1,
"text" => '客人的工作行业',
"selectedAnswer" => $config['defaultAnswer'],
"answerChoiceList" => [
[ "question_number" => 1, "number" => 1, "text" => '学校' ],
[ "question_number" => 1, "number" => 2, "text" => '知名企业' ],
[ "question_number" => 1, "number" => 3, "text" => '自己开公司' ],
[ "question_number" => 1, "number" => 4, "text" => '律师' ],
[ "question_number" => 1, "number" => 5, "text" => '医生' ],
[ "question_number" => 1, "number" => 6, "text" => '工程师' ],
[ "question_number" => 1, "number" => 7, "text" => '军事行业' ],
[ "question_number" => 1, "number" => 8, "text" => '房地产' ],
[ "question_number" => 1, "number" => 9, "text" => '公益机构' ],
[ "question_number" => 1, "number" => 10, "text" => '自由职业' ],
[ "question_number" => 1, "number" => 11, "text" => '其它' ]
]
],
[
"category" => 1,
"number" => 2,
"text" => '客人的工作职位',
"selectedAnswer" => $config['defaultAnswer'],
"answerChoiceList" => [
[ "question_number" => 2, "number" => 12, "text" => '高管' ],
[ "question_number" => 2, "number" => 13, "text" => '大学教授' ],
[ "question_number" => 2, "number" => 14, "text" => 'CEO' ],
[ "question_number" => 2, "number" => 15, "text" => '普通员工' ],
[ "question_number" => 2, "number" => 16, "text" => '其它' ]
]
],
[
"category" => 2,
"number" => 3,
"text" => '你选择来中国的原因是什么?',
"selectedAnswer" => $config['defaultAnswer'],
"answerChoiceList" => [
[ "question_number" => 3, "number" => 17, "text" => '看望在中国/亚洲工作或学习的亲朋好友' ],
[ "question_number" => 3, "number" => 18, "text" => '有家人在学中文想到中国看看' ],
[ "question_number" => 3, "number" => 19, "text" => '家人来中国/亚洲出差' ],
[ "question_number" => 3, "number" => 20, "text" => '身边有中国的朋友经常提起' ],
[ "question_number" => 3, "number" => 21, "text" => '带孩子来中国长见识' ],
[ "question_number" => 3, "number" => 22, "text" => '对中国的文化风景感兴趣' ],
[ "question_number" => 3, "number" => 23, "text" => '其它' ]
]
],
[
"category" => 2,
"number" => 4,
"text" => '你什么时候开始考虑来中国旅行?',
"selectedAnswer" => $config['defaultAnswer'],
"answerChoiceList" => [
[ "question_number" => 4, "number" => 24, "text" => '半年前' ],
[ "question_number" => 4, "number" => 25, "text" => '一年前' ],
[ "question_number" => 4, "number" => 26, "text" => '2年前' ],
[ "question_number" => 4, "number" => 27, "text" => '其它' ]
]
],
[
"category" => 2,
"number" => 5,
"text" => '你计划中国旅行最大的挑战是什么?',
"selectedAnswer" => $config['defaultAnswer'],
"answerChoiceList" => [
[ "question_number" => 5, "number" => 28, "text" => '协调一家人的出行时间' ],
[ "question_number" => 5, "number" => 29, "text" => '中国太大行程安排复杂,无精力计划' ],
[ "question_number" => 5, "number" => 30, "text" => '控制预算' ],
[ "question_number" => 5, "number" => 31, "text" => '孩子需求难满足' ],
[ "question_number" => 5, "number" => 32, "text" => '国际航班飞行时间太长' ],
[ "question_number" => 5, "number" => 33, "text" => '中国的安全问题' ],
[ "question_number" => 5, "number" => 34, "text" => '语言不通' ],
[ "question_number" => 5, "number" => 35, "text" => '签证麻烦' ],
[ "question_number" => 5, "number" => 36, "text" => '无法翻墙' ],
[ "question_number" => 5, "number" => 37, "text" => '其它' ]
]
],
// 使用场景如何找到CH和为何选择CH
[
"category" => 3,
"number" => 6,
"text" => '你从哪里知道China Highlights',
"selectedAnswer" => $config['defaultAnswer'],
"answerChoiceList" => [
[ "question_number" => 6, "number" => 38, "text" => 'Google搜索' ],
[ "question_number" => 6, "number" => 39, "text" => '中国太大行程安排复杂,无精力计划' ],
[ "question_number" => 6, "number" => 40, "text" => 'TA网站 ' ],
[ "question_number" => 6, "number" => 41, "text" => '旅游博客' ],
[ "question_number" => 6, "number" => 42, "text" => '朋友推荐' ],
[ "question_number" => 6, "number" => 43, "text" => '其它' ]
]
],
[
"category" => 3,
"number" => 7,
"text" => '出国旅行时,通常你的旅行方式是什么?',
"selectedAnswer" => $config['defaultAnswer'],
"answerChoiceList" => [
[ "question_number" => 7, "number" => 44, "text" => '自由行' ],
[ "question_number" => 7, "number" => 45, "text" => '旅行社跟团' ],
[ "question_number" => 7, "number" => 46, "text" => '旅行社 ' ],
[ "question_number" => 7, "number" => 47, "text" => '视目的地决定是否使用旅行社' ],
[ "question_number" => 7, "number" => 48, "text" => '其它' ]
]
],
[
"category" => 3,
"number" => 8,
"text" => '你一般从哪里获取旅行资讯?',
"selectedAnswer" => $config['defaultAnswer'],
"answerChoiceList" => [
[ "question_number" => 8, "number" => 49, "text" => 'Google' ],
[ "question_number" => 8, "number" => 50, "text" => '朋友' ],
[ "question_number" => 8, "number" => 51, "text" => '社交媒体如 Facebook, Instagram, Pinterests' ],
[ "question_number" => 8, "number" => 52, "text" => '旅行杂志' ],
[ "question_number" => 8, "number" => 53, "text" => '其它' ]
]
],
[
"category" => 3,
"number" => 9,
"text" => '你为何决定选择China highlights ?',
"selectedAnswer" => $config['defaultAnswer'],
"answerChoiceList" => [
[ "question_number" => 9, "number" => 54, "text" => '外联专业,回复速度快' ],
[ "question_number" => 9, "number" => 55, "text" => '朋友推荐CH' ],
[ "question_number" => 9, "number" => 56, "text" => 'TA好评高' ],
[ "question_number" => 9, "number" => 57, "text" => '价格合理' ],
[ "question_number" => 9, "number" => 58, "text" => '公司可信任' ],
[ "question_number" => 9, "number" => 59, "text" => '其它' ]
]
],
// 观点和机会对CH的评价与期望、重回亚洲的可能性,
[
"category" => 4,
"number" => 10,
"text" => '你认为CH哪里做得比较好',
"selectedAnswer" => $config['defaultAnswer'],
"answerChoiceList" => [
[ "question_number" => 10, "number" => 60, "text" => '安排的体验独特' ],
[ "question_number" => 10, "number" => 61, "text" => '行程衔接好' ],
[ "question_number" => 10, "number" => 62, "text" => '导游专业' ],
[ "question_number" => 10, "number" => 63, "text" => '外联专业' ],
[ "question_number" => 10, "number" => 64, "text" => '网站专业和丰富' ],
[ "question_number" => 10, "number" => 65, "text" => 'TA好评多' ],
[ "question_number" => 10, "number" => 66, "text" => '其它' ]
]
],
[
"category" => 4,
"number" => 11,
"text" => '你认为CH有哪些地方可以改进',
"selectedAnswer" => $config['defaultAnswer'],
"answerChoiceList" => [
[ "question_number" => 11, "number" => 67, "text" => '导游讲解的深度和趣味性' ],
[ "question_number" => 11, "number" => 68, "text" => '实际走团安排更灵活' ],
[ "question_number" => 11, "number" => 69, "text" => '车辆的舒适度和干净程度' ],
[ "question_number" => 11, "number" => 70, "text" => '酒店的选择' ],
[ "question_number" => 11, "number" => 71, "text" => '出发前来中国的常识提醒' ],
[ "question_number" => 11, "number" => 72, "text" => '其它' ]
]
],
[
"category" => 4,
"number" => 12,
"text" => '未来两年你是否考虑再来亚洲?期待去哪些目的地?',
"selectedAnswer" => $config['defaultAnswer'],
"answerChoiceList" => [
[ "question_number" => 12, "number" => 73, "text" => '不考虑' ],
[ "question_number" => 12, "number" => 74, "text" => '考虑' ],
[ "question_number" => 12, "number" => 75, "text" => '其它计划' ]
]
]
];

@ -0,0 +1,20 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
| -------------------------------------------------------------------------
| Hooks
| -------------------------------------------------------------------------
| This file lets you define "hooks" to extend CI without hacking the core
| files. Please see the user guide for info:
|
| https://codeigniter.com/user_guide/general/hooks.html
|
*/
$hook['post_controller_constructor'] = array(
'class' => 'LoginAuth',
'function' => 'auth_trigger',
'filename' => 'loginAuth.php',
'filepath' => 'hooks',
'params' => array()
);

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

@ -0,0 +1,19 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
| -------------------------------------------------------------------------
| Memcached settings
| -------------------------------------------------------------------------
| Your Memcached servers can be specified below.
|
| See: https://codeigniter.com/user_guide/libraries/caching.html#memcached
|
*/
$config = array(
'default' => array(
'hostname' => '127.0.0.1',
'port' => '11211',
'weight' => '1',
),
);

@ -0,0 +1,84 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
|--------------------------------------------------------------------------
| Enable/Disable Migrations
|--------------------------------------------------------------------------
|
| Migrations are disabled by default for security reasons.
| You should enable migrations whenever you intend to do a schema migration
| and disable it back when you're done.
|
*/
$config['migration_enabled'] = FALSE;
/*
|--------------------------------------------------------------------------
| Migration Type
|--------------------------------------------------------------------------
|
| Migration file names may be based on a sequential identifier or on
| a timestamp. Options are:
|
| 'sequential' = Sequential migration naming (001_add_blog.php)
| 'timestamp' = Timestamp migration naming (20121031104401_add_blog.php)
| Use timestamp format YYYYMMDDHHIISS.
|
| Note: If this configuration value is missing the Migration library
| defaults to 'sequential' for backward compatibility with CI2.
|
*/
$config['migration_type'] = 'timestamp';
/*
|--------------------------------------------------------------------------
| Migrations table
|--------------------------------------------------------------------------
|
| This is the name of the table that will store the current migrations state.
| When migrations runs it will store in a database table which migration
| level the system is at. It then compares the migration level in this
| table to the $config['migration_version'] if they are not the same it
| will migrate up. This must be set.
|
*/
$config['migration_table'] = 'migrations';
/*
|--------------------------------------------------------------------------
| Auto Migrate To Latest
|--------------------------------------------------------------------------
|
| If this is set to TRUE when you load the migrations class and have
| $config['migration_enabled'] set to TRUE the system will auto migrate
| to your latest migration (whatever $config['migration_version'] is
| set to). This way you do not have to call migrations anywhere else
| in your code to have the latest migration.
|
*/
$config['migration_auto_latest'] = FALSE;
/*
|--------------------------------------------------------------------------
| Migrations version
|--------------------------------------------------------------------------
|
| This is used to set migration version that the file system should be on.
| If you run $this->migration->current() this is the version that schema will
| be upgraded / downgraded to.
|
*/
$config['migration_version'] = 0;
/*
|--------------------------------------------------------------------------
| Migrations Path
|--------------------------------------------------------------------------
|
| Path to your migrations folder.
| Typically, it will be within your application path.
| Also, writing permission is required within the migrations path.
|
*/
$config['migration_path'] = APPPATH.'migrations/';

@ -0,0 +1,183 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| MIME TYPES
| -------------------------------------------------------------------
| This file contains an array of mime types. It is used by the
| Upload class to help identify allowed file types.
|
*/
return array(
'hqx' => array('application/mac-binhex40', 'application/mac-binhex', 'application/x-binhex40', 'application/x-mac-binhex40'),
'cpt' => 'application/mac-compactpro',
'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain'),
'bin' => array('application/macbinary', 'application/mac-binary', 'application/octet-stream', 'application/x-binary', 'application/x-macbinary'),
'dms' => 'application/octet-stream',
'lha' => 'application/octet-stream',
'lzh' => 'application/octet-stream',
'exe' => array('application/octet-stream', 'application/x-msdownload'),
'class' => 'application/octet-stream',
'psd' => array('application/x-photoshop', 'image/vnd.adobe.photoshop'),
'so' => 'application/octet-stream',
'sea' => 'application/octet-stream',
'dll' => 'application/octet-stream',
'oda' => 'application/oda',
'pdf' => array('application/pdf', 'application/force-download', 'application/x-download', 'binary/octet-stream'),
'ai' => array('application/pdf', 'application/postscript'),
'eps' => 'application/postscript',
'ps' => 'application/postscript',
'smi' => 'application/smil',
'smil' => 'application/smil',
'mif' => 'application/vnd.mif',
'xls' => array('application/vnd.ms-excel', 'application/msexcel', 'application/x-msexcel', 'application/x-ms-excel', 'application/x-excel', 'application/x-dos_ms_excel', 'application/xls', 'application/x-xls', 'application/excel', 'application/download', 'application/vnd.ms-office', 'application/msword'),
'ppt' => array('application/powerpoint', 'application/vnd.ms-powerpoint', 'application/vnd.ms-office', 'application/msword'),
'pptx' => array('application/vnd.openxmlformats-officedocument.presentationml.presentation', 'application/x-zip', 'application/zip'),
'wbxml' => 'application/wbxml',
'wmlc' => 'application/wmlc',
'dcr' => 'application/x-director',
'dir' => 'application/x-director',
'dxr' => 'application/x-director',
'dvi' => 'application/x-dvi',
'gtar' => 'application/x-gtar',
'gz' => 'application/x-gzip',
'gzip' => 'application/x-gzip',
'php' => array('application/x-httpd-php', 'application/php', 'application/x-php', 'text/php', 'text/x-php', 'application/x-httpd-php-source'),
'php4' => 'application/x-httpd-php',
'php3' => 'application/x-httpd-php',
'phtml' => 'application/x-httpd-php',
'phps' => 'application/x-httpd-php-source',
'js' => array('application/x-javascript', 'text/plain'),
'swf' => 'application/x-shockwave-flash',
'sit' => 'application/x-stuffit',
'tar' => 'application/x-tar',
'tgz' => array('application/x-tar', 'application/x-gzip-compressed'),
'z' => 'application/x-compress',
'xhtml' => 'application/xhtml+xml',
'xht' => 'application/xhtml+xml',
'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed', 'application/s-compressed', 'multipart/x-zip'),
'rar' => array('application/x-rar', 'application/rar', 'application/x-rar-compressed'),
'mid' => 'audio/midi',
'midi' => 'audio/midi',
'mpga' => 'audio/mpeg',
'mp2' => 'audio/mpeg',
'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'),
'aif' => array('audio/x-aiff', 'audio/aiff'),
'aiff' => array('audio/x-aiff', 'audio/aiff'),
'aifc' => 'audio/x-aiff',
'ram' => 'audio/x-pn-realaudio',
'rm' => 'audio/x-pn-realaudio',
'rpm' => 'audio/x-pn-realaudio-plugin',
'ra' => 'audio/x-realaudio',
'rv' => 'video/vnd.rn-realvideo',
'wav' => array('audio/x-wav', 'audio/wave', 'audio/wav'),
'bmp' => array('image/bmp', 'image/x-bmp', 'image/x-bitmap', 'image/x-xbitmap', 'image/x-win-bitmap', 'image/x-windows-bmp', 'image/ms-bmp', 'image/x-ms-bmp', 'application/bmp', 'application/x-bmp', 'application/x-win-bitmap'),
'gif' => 'image/gif',
'jpeg' => array('image/jpeg', 'image/pjpeg'),
'jpg' => array('image/jpeg', 'image/pjpeg'),
'jpe' => array('image/jpeg', 'image/pjpeg'),
'jp2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
'j2k' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
'jpf' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
'jpg2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
'jpx' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
'jpm' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
'mj2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
'mjp2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
'png' => array('image/png', 'image/x-png'),
'tiff' => 'image/tiff',
'tif' => 'image/tiff',
'css' => array('text/css', 'text/plain'),
'html' => array('text/html', 'text/plain'),
'htm' => array('text/html', 'text/plain'),
'shtml' => array('text/html', 'text/plain'),
'txt' => 'text/plain',
'text' => 'text/plain',
'log' => array('text/plain', 'text/x-log'),
'rtx' => 'text/richtext',
'rtf' => 'text/rtf',
'xml' => array('application/xml', 'text/xml', 'text/plain'),
'xsl' => array('application/xml', 'text/xsl', 'text/xml'),
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'mpe' => 'video/mpeg',
'qt' => 'video/quicktime',
'mov' => 'video/quicktime',
'avi' => array('video/x-msvideo', 'video/msvideo', 'video/avi', 'application/x-troff-msvideo'),
'movie' => 'video/x-sgi-movie',
'doc' => array('application/msword', 'application/vnd.ms-office'),
'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword', 'application/x-zip'),
'dot' => array('application/msword', 'application/vnd.ms-office'),
'dotx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword'),
'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/vnd.ms-excel', 'application/msword', 'application/x-zip'),
'word' => array('application/msword', 'application/octet-stream'),
'xl' => 'application/excel',
'eml' => 'message/rfc822',
'json' => array('application/json', 'text/json'),
'pem' => array('application/x-x509-user-cert', 'application/x-pem-file', 'application/octet-stream'),
'p10' => array('application/x-pkcs10', 'application/pkcs10'),
'p12' => 'application/x-pkcs12',
'p7a' => 'application/x-pkcs7-signature',
'p7c' => array('application/pkcs7-mime', 'application/x-pkcs7-mime'),
'p7m' => array('application/pkcs7-mime', 'application/x-pkcs7-mime'),
'p7r' => 'application/x-pkcs7-certreqresp',
'p7s' => 'application/pkcs7-signature',
'crt' => array('application/x-x509-ca-cert', 'application/x-x509-user-cert', 'application/pkix-cert'),
'crl' => array('application/pkix-crl', 'application/pkcs-crl'),
'der' => 'application/x-x509-ca-cert',
'kdb' => 'application/octet-stream',
'pgp' => 'application/pgp',
'gpg' => 'application/gpg-keys',
'sst' => 'application/octet-stream',
'csr' => 'application/octet-stream',
'rsa' => 'application/x-pkcs7',
'cer' => array('application/pkix-cert', 'application/x-x509-ca-cert'),
'3g2' => 'video/3gpp2',
'3gp' => array('video/3gp', 'video/3gpp'),
'mp4' => 'video/mp4',
'm4a' => 'audio/x-m4a',
'f4v' => array('video/mp4', 'video/x-f4v'),
'flv' => 'video/x-flv',
'webm' => 'video/webm',
'aac' => 'audio/x-acc',
'm4u' => 'application/vnd.mpegurl',
'm3u' => 'text/plain',
'xspf' => 'application/xspf+xml',
'vlc' => 'application/videolan',
'wmv' => array('video/x-ms-wmv', 'video/x-ms-asf'),
'au' => 'audio/x-au',
'ac3' => 'audio/ac3',
'flac' => 'audio/x-flac',
'ogg' => array('audio/ogg', 'video/ogg', 'application/ogg'),
'kmz' => array('application/vnd.google-earth.kmz', 'application/zip', 'application/x-zip'),
'kml' => array('application/vnd.google-earth.kml+xml', 'application/xml', 'text/xml'),
'ics' => 'text/calendar',
'ical' => 'text/calendar',
'zsh' => 'text/x-scriptzsh',
'7zip' => array('application/x-compressed', 'application/x-zip-compressed', 'application/zip', 'multipart/x-zip'),
'cdr' => array('application/cdr', 'application/coreldraw', 'application/x-cdr', 'application/x-coreldraw', 'image/cdr', 'image/x-cdr', 'zz-application/zz-winassoc-cdr'),
'wma' => array('audio/x-ms-wma', 'video/x-ms-asf'),
'jar' => array('application/java-archive', 'application/x-java-application', 'application/x-jar', 'application/x-compressed'),
'svg' => array('image/svg+xml', 'application/xml', 'text/xml'),
'vcf' => 'text/x-vcard',
'srt' => array('text/srt', 'text/plain'),
'vtt' => array('text/vtt', 'text/plain'),
'ico' => array('image/x-icon', 'image/x-ico', 'image/vnd.microsoft.icon'),
'odc' => 'application/vnd.oasis.opendocument.chart',
'otc' => 'application/vnd.oasis.opendocument.chart-template',
'odf' => 'application/vnd.oasis.opendocument.formula',
'otf' => 'application/vnd.oasis.opendocument.formula-template',
'odg' => 'application/vnd.oasis.opendocument.graphics',
'otg' => 'application/vnd.oasis.opendocument.graphics-template',
'odi' => 'application/vnd.oasis.opendocument.image',
'oti' => 'application/vnd.oasis.opendocument.image-template',
'odp' => 'application/vnd.oasis.opendocument.presentation',
'otp' => 'application/vnd.oasis.opendocument.presentation-template',
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
'odt' => 'application/vnd.oasis.opendocument.text',
'odm' => 'application/vnd.oasis.opendocument.text-master',
'ott' => 'application/vnd.oasis.opendocument.text-template',
'oth' => 'application/vnd.oasis.opendocument.text-web'
);

@ -0,0 +1,14 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
| -------------------------------------------------------------------------
| Profiler Sections
| -------------------------------------------------------------------------
| This file lets you determine whether or not various sections of Profiler
| data are displayed when the Profiler is enabled.
| Please see the user guide for info:
|
| https://codeigniter.com/user_guide/general/profiling.html
|
*/

@ -0,0 +1,54 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
| -------------------------------------------------------------------------
| URI ROUTING
| -------------------------------------------------------------------------
| This file lets you re-map URI requests to specific controller functions.
|
| Typically there is a one-to-one relationship between a URL string
| and its corresponding controller class/method. The segments in a
| URL normally follow this pattern:
|
| example.com/class/method/id/
|
| In some instances, however, you may want to remap this relationship
| so that a different class/function is called than the one
| corresponding to the URL.
|
| Please see the user guide for complete details:
|
| https://codeigniter.com/user_guide/general/routing.html
|
| -------------------------------------------------------------------------
| RESERVED ROUTES
| -------------------------------------------------------------------------
|
| There are three reserved routes:
|
| $route['default_controller'] = 'welcome';
|
| This route indicates which controller class should be loaded if the
| URI contains no data. In the above example, the "welcome" class
| would be loaded.
|
| $route['404_override'] = 'errors/page_missing';
|
| This route will tell the Router which controller/method to use if those
| provided in the URL cannot be matched to a valid route.
|
| $route['translate_uri_dashes'] = FALSE;
|
| This is not exactly a route, but allows you to automatically route
| controller and method names that contain dashes. '-' isn't a valid
| class or method name character, so it requires translation.
| When you set this option to TRUE, it will replace ALL dashes in the
| controller and method URI segments.
|
| Examples: my-controller/index -> my_controller/index
| my-controller/my-method -> my_controller/my_method
*/
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = TRUE;

@ -0,0 +1,64 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| SMILEYS
| -------------------------------------------------------------------
| This file contains an array of smileys for use with the emoticon helper.
| Individual images can be used to replace multiple smileys. For example:
| :-) and :) use the same image replacement.
|
| Please see user guide for more info:
| https://codeigniter.com/user_guide/helpers/smiley_helper.html
|
*/
$smileys = array(
// smiley image name width height alt
':-)' => array('grin.gif', '19', '19', 'grin'),
':lol:' => array('lol.gif', '19', '19', 'LOL'),
':cheese:' => array('cheese.gif', '19', '19', 'cheese'),
':)' => array('smile.gif', '19', '19', 'smile'),
';-)' => array('wink.gif', '19', '19', 'wink'),
';)' => array('wink.gif', '19', '19', 'wink'),
':smirk:' => array('smirk.gif', '19', '19', 'smirk'),
':roll:' => array('rolleyes.gif', '19', '19', 'rolleyes'),
':-S' => array('confused.gif', '19', '19', 'confused'),
':wow:' => array('surprise.gif', '19', '19', 'surprised'),
':bug:' => array('bigsurprise.gif', '19', '19', 'big surprise'),
':-P' => array('tongue_laugh.gif', '19', '19', 'tongue laugh'),
'%-P' => array('tongue_rolleye.gif', '19', '19', 'tongue rolleye'),
';-P' => array('tongue_wink.gif', '19', '19', 'tongue wink'),
':P' => array('raspberry.gif', '19', '19', 'raspberry'),
':blank:' => array('blank.gif', '19', '19', 'blank stare'),
':long:' => array('longface.gif', '19', '19', 'long face'),
':ohh:' => array('ohh.gif', '19', '19', 'ohh'),
':grrr:' => array('grrr.gif', '19', '19', 'grrr'),
':gulp:' => array('gulp.gif', '19', '19', 'gulp'),
'8-/' => array('ohoh.gif', '19', '19', 'oh oh'),
':down:' => array('downer.gif', '19', '19', 'downer'),
':red:' => array('embarrassed.gif', '19', '19', 'red face'),
':sick:' => array('sick.gif', '19', '19', 'sick'),
':shut:' => array('shuteye.gif', '19', '19', 'shut eye'),
':-/' => array('hmm.gif', '19', '19', 'hmmm'),
'>:(' => array('mad.gif', '19', '19', 'mad'),
':mad:' => array('mad.gif', '19', '19', 'mad'),
'>:-(' => array('angry.gif', '19', '19', 'angry'),
':angry:' => array('angry.gif', '19', '19', 'angry'),
':zip:' => array('zip.gif', '19', '19', 'zipper'),
':kiss:' => array('kiss.gif', '19', '19', 'kiss'),
':ahhh:' => array('shock.gif', '19', '19', 'shock'),
':coolsmile:' => array('shade_smile.gif', '19', '19', 'cool smile'),
':coolsmirk:' => array('shade_smirk.gif', '19', '19', 'cool smirk'),
':coolgrin:' => array('shade_grin.gif', '19', '19', 'cool grin'),
':coolhmm:' => array('shade_hmm.gif', '19', '19', 'cool hmm'),
':coolmad:' => array('shade_mad.gif', '19', '19', 'cool mad'),
':coolcheese:' => array('shade_cheese.gif', '19', '19', 'cool cheese'),
':vampire:' => array('vampire.gif', '19', '19', 'vampire'),
':snake:' => array('snake.gif', '19', '19', 'snake'),
':exclaim:' => array('exclaim.gif', '19', '19', 'exclaim'),
':question:' => array('question.gif', '19', '19', 'question')
);

@ -0,0 +1,214 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| USER AGENT TYPES
| -------------------------------------------------------------------
| This file contains four arrays of user agent data. It is used by the
| User Agent Class to help identify browser, platform, robot, and
| mobile device data. The array keys are used to identify the device
| and the array values are used to set the actual name of the item.
*/
$platforms = array(
'windows nt 10.0' => 'Windows 10',
'windows nt 6.3' => 'Windows 8.1',
'windows nt 6.2' => 'Windows 8',
'windows nt 6.1' => 'Windows 7',
'windows nt 6.0' => 'Windows Vista',
'windows nt 5.2' => 'Windows 2003',
'windows nt 5.1' => 'Windows XP',
'windows nt 5.0' => 'Windows 2000',
'windows nt 4.0' => 'Windows NT 4.0',
'winnt4.0' => 'Windows NT 4.0',
'winnt 4.0' => 'Windows NT',
'winnt' => 'Windows NT',
'windows 98' => 'Windows 98',
'win98' => 'Windows 98',
'windows 95' => 'Windows 95',
'win95' => 'Windows 95',
'windows phone' => 'Windows Phone',
'windows' => 'Unknown Windows OS',
'android' => 'Android',
'blackberry' => 'BlackBerry',
'iphone' => 'iOS',
'ipad' => 'iOS',
'ipod' => 'iOS',
'os x' => 'Mac OS X',
'ppc mac' => 'Power PC Mac',
'freebsd' => 'FreeBSD',
'ppc' => 'Macintosh',
'linux' => 'Linux',
'debian' => 'Debian',
'sunos' => 'Sun Solaris',
'beos' => 'BeOS',
'apachebench' => 'ApacheBench',
'aix' => 'AIX',
'irix' => 'Irix',
'osf' => 'DEC OSF',
'hp-ux' => 'HP-UX',
'netbsd' => 'NetBSD',
'bsdi' => 'BSDi',
'openbsd' => 'OpenBSD',
'gnu' => 'GNU/Linux',
'unix' => 'Unknown Unix OS',
'symbian' => 'Symbian OS'
);
// The order of this array should NOT be changed. Many browsers return
// multiple browser types so we want to identify the sub-type first.
$browsers = array(
'OPR' => 'Opera',
'Flock' => 'Flock',
'Edge' => 'Spartan',
'Chrome' => 'Chrome',
// Opera 10+ always reports Opera/9.80 and appends Version/<real version> to the user agent string
'Opera.*?Version' => 'Opera',
'Opera' => 'Opera',
'MSIE' => 'Internet Explorer',
'Internet Explorer' => 'Internet Explorer',
'Trident.* rv' => 'Internet Explorer',
'Shiira' => 'Shiira',
'Firefox' => 'Firefox',
'Chimera' => 'Chimera',
'Phoenix' => 'Phoenix',
'Firebird' => 'Firebird',
'Camino' => 'Camino',
'Netscape' => 'Netscape',
'OmniWeb' => 'OmniWeb',
'Safari' => 'Safari',
'Mozilla' => 'Mozilla',
'Konqueror' => 'Konqueror',
'icab' => 'iCab',
'Lynx' => 'Lynx',
'Links' => 'Links',
'hotjava' => 'HotJava',
'amaya' => 'Amaya',
'IBrowse' => 'IBrowse',
'Maxthon' => 'Maxthon',
'Ubuntu' => 'Ubuntu Web Browser'
);
$mobiles = array(
// legacy array, old values commented out
'mobileexplorer' => 'Mobile Explorer',
// 'openwave' => 'Open Wave',
// 'opera mini' => 'Opera Mini',
// 'operamini' => 'Opera Mini',
// 'elaine' => 'Palm',
'palmsource' => 'Palm',
// 'digital paths' => 'Palm',
// 'avantgo' => 'Avantgo',
// 'xiino' => 'Xiino',
'palmscape' => 'Palmscape',
// 'nokia' => 'Nokia',
// 'ericsson' => 'Ericsson',
// 'blackberry' => 'BlackBerry',
// 'motorola' => 'Motorola'
// Phones and Manufacturers
'motorola' => 'Motorola',
'nokia' => 'Nokia',
'palm' => 'Palm',
'iphone' => 'Apple iPhone',
'ipad' => 'iPad',
'ipod' => 'Apple iPod Touch',
'sony' => 'Sony Ericsson',
'ericsson' => 'Sony Ericsson',
'blackberry' => 'BlackBerry',
'cocoon' => 'O2 Cocoon',
'blazer' => 'Treo',
'lg' => 'LG',
'amoi' => 'Amoi',
'xda' => 'XDA',
'mda' => 'MDA',
'vario' => 'Vario',
'htc' => 'HTC',
'samsung' => 'Samsung',
'sharp' => 'Sharp',
'sie-' => 'Siemens',
'alcatel' => 'Alcatel',
'benq' => 'BenQ',
'ipaq' => 'HP iPaq',
'mot-' => 'Motorola',
'playstation portable' => 'PlayStation Portable',
'playstation 3' => 'PlayStation 3',
'playstation vita' => 'PlayStation Vita',
'hiptop' => 'Danger Hiptop',
'nec-' => 'NEC',
'panasonic' => 'Panasonic',
'philips' => 'Philips',
'sagem' => 'Sagem',
'sanyo' => 'Sanyo',
'spv' => 'SPV',
'zte' => 'ZTE',
'sendo' => 'Sendo',
'nintendo dsi' => 'Nintendo DSi',
'nintendo ds' => 'Nintendo DS',
'nintendo 3ds' => 'Nintendo 3DS',
'wii' => 'Nintendo Wii',
'open web' => 'Open Web',
'openweb' => 'OpenWeb',
// Operating Systems
'android' => 'Android',
'symbian' => 'Symbian',
'SymbianOS' => 'SymbianOS',
'elaine' => 'Palm',
'series60' => 'Symbian S60',
'windows ce' => 'Windows CE',
// Browsers
'obigo' => 'Obigo',
'netfront' => 'Netfront Browser',
'openwave' => 'Openwave Browser',
'mobilexplorer' => 'Mobile Explorer',
'operamini' => 'Opera Mini',
'opera mini' => 'Opera Mini',
'opera mobi' => 'Opera Mobile',
'fennec' => 'Firefox Mobile',
// Other
'digital paths' => 'Digital Paths',
'avantgo' => 'AvantGo',
'xiino' => 'Xiino',
'novarra' => 'Novarra Transcoder',
'vodafone' => 'Vodafone',
'docomo' => 'NTT DoCoMo',
'o2' => 'O2',
// Fallback
'mobile' => 'Generic Mobile',
'wireless' => 'Generic Mobile',
'j2me' => 'Generic Mobile',
'midp' => 'Generic Mobile',
'cldc' => 'Generic Mobile',
'up.link' => 'Generic Mobile',
'up.browser' => 'Generic Mobile',
'smartphone' => 'Generic Mobile',
'cellphone' => 'Generic Mobile'
);
// There are hundreds of bots but these are the most common.
$robots = array(
'googlebot' => 'Googlebot',
'msnbot' => 'MSNBot',
'baiduspider' => 'Baiduspider',
'bingbot' => 'Bing',
'slurp' => 'Inktomi Slurp',
'yahoo' => 'Yahoo',
'ask jeeves' => 'Ask Jeeves',
'fastcrawler' => 'FastCrawler',
'infoseek' => 'InfoSeek Robot 1.0',
'lycos' => 'Lycos',
'yandex' => 'YandexBot',
'mediapartners-google' => 'MediaPartners Google',
'CRAZYWEBCRAWLER' => 'Crazy Webcrawler',
'adsbot-google' => 'AdsBot Google',
'feedfetcher-google' => 'Feedfetcher Google',
'curious george' => 'Curious George',
'ia_archiver' => 'Alexa Crawler',
'MJ12bot' => 'Majestic-12',
'Uptimebot' => 'Uptimebot'
);

@ -0,0 +1,61 @@
<?php
$config["sign_type"] = "HMAC-SHA256";
$config["trade_type"] = "NATIVE";
$config["currency"] = "CNY";
$config["currency_unit"] = 100;
$config["method_code"] = 15016;
$config["send_notify_url"] = "https://www.mycht.cn/webht.php/apps/pay/paymentservice/send_notify";
$config['url_domain'] = "https://api.weixin.qq.com";
$config['qrcode_src_prefix'] = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=";
/*!
* 各账号的设置
*/
$config['all_account'] = "cht,trippest";
// test
// $config['test']["notify_url"] = "https://www.mycht.cn/webht.php/apps/pay/wxpayservice/notify/test";
// $config['test']["app_id"] = "wx426b3015555a46be";
// $config['test']["mch_id"] = "1900009851";
// $config['test']["key"] = "8934e7d15453e97507ef794cf7b0519d";
// $config['test']["app_secret"] = "7813490da6f1265e4901ffb80afaa36f";
// // test ldj__yt sandbox
// $config['lyt']["notify_url"] = "https://www.mycht.cn/webht.php/apps/pay/wxpayservice/notify/lyt";
// $config['lyt']["app_id"] = "wx5a71eb521a3b9cc2";
// $config['lyt']["app_secret"] = "686c866ee37da085cffd8c51e0a286f8";
// $config['lyt']["token"] = "ef9655c079b6443f9153d0ed95037bb5";
// // $config['lyt']["mch_id"] = "1900009851";
// // $config['lyt']["key"] = "8934e7d15453e97507ef794cf7b0519d";
// $config['lyt']['auto_reply'] = array(
// "reply_follow" => "Thank you for following Trippest. You can get the latest updates of Trippest tours, news, and promos. You can also track your trip here."
// ,"reply_text" => "Thanks for your message. We will reply to you as soon as possible (usually within 24 hours)."
// );
// Trippest
$config['trippest']["notify_url"] = "https://www.mycht.cn/webht.php/apps/pay/wxpayservice/notify/trippest";
$config['trippest']["app_id"] = "wx7e605820faf98a05";
$config['trippest']["mch_id"] = "1528541381";
$config['trippest']["key"] = "b6f4db121410468e814d812c6c641efd";
$config['trippest']["app_secret"] = "e3c00039f11b1c557df62d703bff28d6";
$config['trippest']["token"] = "ef9655c079b6443f9153d0ed95037bb5";
$config['trippest']['auto_reply'] = array(
"reply_follow" => "Welcome to Trippest! You can book China day trips, activities, things to do, sightseeing tours and more with us. We also offer tours in Thailand, Vietnam, Cambodia, India…etc.
Over 30,000 people traveled with Trippest and posted thousands of high 5 stars reviews online. Come and lets get your trip started..."
,"reply_text" => "Thank you for the question. Please wait for a while. You can also leave an Email address and phone number for emergency contact."
,"menu" => array(
"USER_CONTACT" => "Hey, I'm Niko. How may I help you?
You can leave questions here and I'll get back to you very soon.
More ways to contact me:
E-mail: inquiry@trippest.com
WeChat ID: trippest666
Emergency Call: +86 18807734970"
)
);
// ChinaHighlights = China train booking
$config['cht']["notify_url"] = "https://www.mycht.cn/webht.php/apps/pay/wxpayservice/notify/cht";
$config['cht']["app_id"] = "wxd6c8dd69af5128cd";
$config['cht']["mch_id"] = "1353239702";
$config['cht']["key"] = "aada7476b3fecc2c6e33a7c765298516";
$config['cht']["app_secret"] = "";

@ -0,0 +1,738 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Wechat_mp extends CI_Controller
{
// 服务号主体 'trippest'
private $wechat_host;
// 服务号的配置信息
private $wechat_config;
// 服务号账户
private $wechat_operator;
public function __construct()
{
parent::__construct();
$this->load->helper('url_helper');
$this->load->helper('device_helper');
$this->config->load("wechat", true);
$this->load->library('Wechat_lib');
$this->load->library('Bokun_lib');
$this->load->model('Order_model');
$this->load->model('Wechat_service_model');
header('Access-Control-Allow-Origin:*');
}
public function notice($wechat_host)
{
error_reporting(0);
$this->wechat_config = $this->config->item($wechat_host, 'wechat');
$this->wechat_host = $wechat_host;
$get_input = $this->input->get();
$raw_post_data = file_get_contents('php://input');
// empty POST data
if (empty($raw_post_data)) {
return $this->wechat_lib->auth_signature($get_input, $this->wechat_config['token']);
}
$raw_arr = $this->wechat_lib->from_xml($raw_post_data);
$this->wechat_operator = $raw_arr['ToUserName'];
$user_info = $this->Wechat_service_model->get_user(null, $this->wechat_config['app_id'], $raw_arr['FromUserName']);
$insert_db = array(
"wn_hostappid" => $this->wechat_config['app_id'], "wn_useropenid" => $raw_arr['FromUserName'], "wn_wu_id" => $user_info['wu_id'], "wn_msgtype" => $raw_arr['MsgType'], "wn_eventtype" => isset($raw_arr['Event']) ? $raw_arr['Event'] : null, "wn_msgid" => isset($raw_arr['MsgId']) ? $raw_arr['MsgId'] : null, "wn_eventkey" => isset($raw_arr['EventKey']) ? (is_array($raw_arr['EventKey']) ? json_encode($raw_arr['EventKey']) : $raw_arr['EventKey']) : null, "wn_createtime" => date("Y-m-d H:i:s", $raw_arr['CreateTime']), "wn_rawcontent" => json_encode($raw_arr, JSON_UNESCAPED_UNICODE)
);
$this->Wechat_service_model->insert_wechat_notify($insert_db);
// Handle MsgType
switch (strtolower($raw_arr['MsgType'])) {
case 'text':
$this->text_handle($raw_arr);
break;
case 'event':
$this->event_handles($raw_arr);
break;
default:
break;
}
// 确保返回空字符串
return $this->wechat_lib->response_text(null, $raw_arr['FromUserName'], $this->wechat_operator);
}
/**
* 生成带参数的公众号二维码
* @deprecated Move to Wechat_order.php
* @param str 订单主表key
* @param str 公众号的名字, 默认是Trippest.
* @return str 二维码图片地址
*/
public function order_qrcode($coli_sn, $wechat_host)
{
$this->wechat_config = $this->config->item($wechat_host, 'wechat');
$this->wechat_host = $wechat_host;
$url = "/cgi-bin/qrcode/create";
$qrcode_request_info = array(
"action_name" => "QR_STR_SCENE",
"expire_seconds" => 604800,
"action_info" => array("scene" => array("scene_str" => strval($coli_sn)))
);
$qrcode_response_info = json_decode($this->wechat_lib->call_wechat($wechat_host, $url, [], json_encode($qrcode_request_info, JSON_UNESCAPED_UNICODE)), true);
$qrcode_src_url = $this->config->item('qrcode_src_prefix', 'wechat') . urlencode($qrcode_response_info['ticket']);
return $this->output->set_output($qrcode_src_url);
}
/**
* @deprecated 0.1 通过带参数二维码关注的直接绑定,不再需要验证码绑定
* 发送验证码
*/
public function captcha_send()
{
$captcha = rand(100000, 999999);
$mobile = $this->input->get_post('mobile');
$nation = $this->input->get_post('nation');
$openid = $this->input->get_post('openid');
$user_id = $this->input->get_post('userid');
$captcha_column = array(
"wcc_value" => $captcha, "wcc_verifytype" => 'mobile', "wcc_wu_id" => $user_id, "wcc_mobileno" => $mobile, "wcc_nation" => $nation, "wcc_email" => null, "wcc_status" => 0, "wcc_expireseconds" => 300
);
$ret = array("captcha_value" => $captcha);
$this->Wechat_service_model->insert_captcha($captcha_column);
return $this->output->set_content_type('application/json')->set_output(json_encode($ret));
}
/**
* @deprecated 0.1 通过带参数二维码关注的直接绑定,不再需要验证码绑定
* 验证码校验
* @param mixed captcha
* @param mixed $userid
*/
public function captcha_verify()
{
$ret = array(
"verify" => "failed", "failed_reason" => ""
);
$captcha = $this->input->get_post('captcha');
$user_id = $this->input->get_post('userid');
// $order_id = $this->input->get_post('order_id');
// $order_type = $this->input->get_post('order_type');
// verify captcha
$captcha_data = $this->Wechat_service_model->get_verify($user_id, $captcha);
if (empty($captcha_data)) {
$ret['failed_reason'] = "Wrong captcha.";
}
if ($captcha_data['expire_time'] < date("Y-m-d H:i:s")) {
$ret['failed_reason'] = "Captcha expired.";
}
if (strval($captcha_data['wcc_status']) !== '0') {
$ret['failed_reason'] = "Captcha has been used.";
}
if ($ret['failed_reason'] !== '') {
return $this->output->set_content_type('application/json')->set_output(json_encode($ret));
}
// set verify status
$this->Wechat_service_model->set_captcha_pass($captcha_data['wcc_id']);
// new wechat customer
$user_info = $this->Wechat_service_model->get_user($user_id);
$customer_column = array(
"wc_wu_id" => $user_id, "wc_coli_sn" => $user_info['wu_coli_sn'], "wc_htordertype" => $user_info['wu_htordertype']
);
$this->Wechat_service_model->insert_wechat_customer($customer_column);
$ret['verify'] = "success";
unset($ret['failed_reason']);
return $this->output->set_content_type('application/json')->set_output(json_encode($ret));
}
/**
* 页面需要用户授权
* 入口: https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect
* 如果用户同意授权,页面将跳转至 redirect_uri/?code=CODE&state=STATE
* * redirect_uri: 授权后重定向的回调链接地址, 请使用 urlEncode 对链接进行处理
* * scope: 应用授权作用域snsapi_base 不弹出授权页面直接跳转只能获取用户openidsnsapi_userinfo 弹出授权页面可通过openid拿到昵称、性别、所在地。并且 即使在未关注的情况下,只要用户授权,也能获取其信息
* * state: 重定向后会带上state参数开发者可以填写a-zA-Z0-9的参数值最多128字节
*/
/**
* 页面授权, 获取用户openid, userid
* @param mixed code code作为换取access_token的票据每次用户授权带上的code将不一样code只能使用一次5分钟未被使用自动过期。
* 获取access token的返回值:
* * {
* * "access_token":"ACCESS_TOKEN",
* * "expires_in":7200,
* * "refresh_token":"REFRESH_TOKEN", // 用于刷新access_token
* * "openid":"OPENID",
* * "scope":"SCOPE"
* * }
* 刷新access token: https://api.weixin.qq.com/sns/oauth2/refresh_token?appid=APPID&grant_type=refresh_token&refresh_token=REFRESH_TOKEN
*/
/**
* 进入页面后静默登录
* @link `/tours/{city}`
*/
public function page_login($wechat_host)
{
$login_info = $this->get_page_access_token($wechat_host);
return $this->output->set_content_type('application/json')->set_output(json_encode($login_info));
}
/**
* 公众号菜单入口, 直接登录跳转
* @link `My Itinerary`
* 跳转顺序:
* 1. 公众号菜单设置的地址: 页面授权入口[跳转页面参数=page_login | login_now, login_now?state参数区分不同的目标页面]
* 2. 到达login_now, 通过state参数跳转到目标页面
* * * state: [orders:My Itinerary; ]
* ?user_id={id}
* * https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7e605820faf98a05&redirect_uri=http%3A%2F%2Ftrippest.mycht.cn%2Fapi%2Findex.php%2Fwechat-mp%2Flogin-now%2Ftrippest&response_type=code&scope=snsapi_base&state=Beijing#wechat_redirect
*/
public function login_now($wechat_host)
{
// $login_info = array (
// 'access_token' => '33_0XjLimrEnWdSb-cUVowwnQo7vxo-yB4-KWo1qOWLPx5ukXMUA-Bw5WZEzfXuayCEDWfQxQlJTzIMqZ79CTAeOg',
// 'expires_in' => 7200,
// 'refresh_token' => '33_mONKlYbwDcF7ixg0-P31NAcKAYwWNEhjLewwyn09NHOjcFUq-Bu-xHbYEvaRjnaAE4ZGkgYLJe7mgILbsjskNw',
// 'openid' => 'oe2BW1C9G-gmtDyOqwIvOMg8L_FA',
// 'scope' => 'snsapi_userinfo',
// 'user_id' => NULL,
// 'order_id' => NULL,
// 'order_type' => NULL,
// 'head_img' => 'http://thirdwx.qlogo.cn/mmopen/lXEiaQibaXvee79ia4mg0eP0ia0YHLtxNRs1JKpKnkxib7WPvFZtqQbHn7icmVoB90Up0x7A3qiaomovwKOf4lBcPbOmAsGBAOTPeyS/132',
// 'nickname' => 'Lei、OT',
// 'tourdata_v' => '201909111900'); // test:
$login_info = $this->get_page_access_token($wechat_host);
$state_target = $this->input->get_post('state');
switch (strtolower($state_target)) {
case 'orders':
redirect(HOST . "account?userid=" . $login_info['user_id']);
break;
case 'detail':
$path = $this->input->get_post('l'); // l=/order/{coli_sn}/{coli_id}
redirect(HOST . substr($path, 1) . "?userid=" . $login_info['user_id']);
break;
case 'guest':
$path = $this->input->get_post('l');
unset($login_info['access_token']);
unset($login_info['refresh_token']);
// remove first '/'
$redirect_url = HOST . substr($path, 1) . "?userid=" . $login_info['user_id'];
redirect($redirect_url);
break;
default: // cityname=pathname
redirect(HOST . "tours/" . $state_target . "?userid=" . $login_info['user_id']);
break;
}
return;
}
private function get_page_access_token($wechat_host)
{
$this->wechat_config = $this->config->item($wechat_host, 'wechat');
$this->wechat_host = $wechat_host;
$page_access = array("openid" => null);
$userid = $this->input->get_post('userid');
if ($userid === false || $userid === null) {
$userid = null;
$code = $this->input->get_post('code');
$page_access_url = "/sns/oauth2/access_token";
$query = array(
"appid" => $this->wechat_config['app_id'],
"secret" => $this->wechat_config['app_secret'],
"code" => $code,
"grant_type" => 'authorization_code',
);
// $page_access = array (
// 'access_token' => '33_0XjLimrEnWdSb-cUVowwnQo7vxo-yB4-KWo1qOWLPx5ukXMUA-Bw5WZEzfXuayCEDWfQxQlJTzIMqZ79CTAeOg',
// 'expires_in' => 7200,
// 'refresh_token' => '33_mONKlYbwDcF7ixg0-P31NAcKAYwWNEhjLewwyn09NHOjcFUq-Bu-xHbYEvaRjnaAE4ZGkgYLJe7mgILbsjskNw',
// 'openid' => 'oe2BW1C9G-gmtDyOqwIvOMg8L_FA',
// 'scope' => 'snsapi_userinfo');
// test:
$page_access = json_decode($this->wechat_lib->call_wechat($wechat_host, $page_access_url, $query), true);
}
$user_info = $this->Wechat_service_model->get_user($userid, $this->wechat_config['app_id'], $page_access['openid']);
if (empty($user_info) && strval($userid) !== '0') {
$user_info = $this->subscribe_handle(array('FromUserName' => $page_access['openid']), false);
}
$page_access['openid'] = $user_info['wu_useropenid'];
$page_access['user_id'] = $user_info['wu_id'] === null ? 0 : $user_info['wu_id'];
$page_access['order_id'] = $user_info['wu_coli_sn'];
$page_access['order_type'] = $user_info['wu_htordertype'];
$page_access['head_img'] = $user_info['wu_headimg'];
$page_access['nickname'] = $user_info['wu_nickname'];
return $page_access;
}
private function get_user_info($openid)
{
// $access_token = $this->get_access_token();
$url = "/cgi-bin/user/info";
$query = array(
'openid' => $openid,
'lang' => 'en'
);
$user_info_response = json_decode($this->wechat_lib->call_wechat($this->wechat_host, $url, $query), true);
return $user_info_response;
}
private function get_access_token()
{
$url = $this->config->item('url_domain', 'wechat') . "/cgi-bin/token?grant_type=client_credential&appid=" . $this->wechat_config['app_id'] . "&secret=" . $this->wechat_config['app_secret'];
$access_token_arr = json_decode($this->wechat_lib->call_wechat($url), true);
return $access_token_arr['access_token'];
}
private function event_handles($input)
{
switch (strtolower($input['Event'])) {
case 'scan':
$this->scan_handle($input);
break;
case 'subscribe':
$this->subscribe_handle($input);
break;
case 'click':
$this->click_handle($input);
break;
default:
# code...
break;
}
return;
}
private function click_handle($input)
{
$event_key = $input['EventKey'];
$click_memu = $this->wechat_config['auto_reply']['menu'];
if (isset($click_memu[$event_key])) {
$reply_content = $click_memu[$event_key];
return $this->wechat_lib->response_text($reply_content, $input['FromUserName'], $this->wechat_operator);
}
return $this->wechat_lib->response_text();
}
private function subscribe_handle($input, $response = true)
{
if ($response === true) {
$reply_content = $this->wechat_config['auto_reply']['reply_follow'];
$this->wechat_lib->response_text($reply_content, $input['FromUserName'], $this->wechat_operator);
}
$user_info = $this->get_user_info($input['FromUserName']);
$from_order = explode("_", $user_info['qr_scene_str']); // ordersn_ordertype:435021757_27002
$coli_sn = $from_order[0] ? $from_order[0] : null;
$order_type = isset($from_order[1]) ? $from_order[1] : 27002;
$mobile = null;
$email = null;
$nation = null;
/**
* 已绑定过的二维码不能再次绑定其他用户
*/
if ($coli_sn !== null && false === $this->Wechat_service_model->if_order_bound($coli_sn, $order_type)) {
$this->load->model('Order_model');
$contact = $this->Order_model->get_order_contact($coli_sn, strval($order_type));
!empty($contact) ? $mobile = $contact['phone_no'] : null;
!empty($contact) ? $email = $contact['email'] : null;
!empty($contact) ? $nation = $contact['nation'] : null;
} else {
$coli_sn = null;
$order_type = null;
}
$user_column = array(
"wu_mobileno" => $mobile,
"wu_email" => $email,
"wu_nation" => $nation,
"wu_coli_sn" => $coli_sn,
"wu_htordertype" => $order_type,
"wu_hostappid" => $this->wechat_config['app_id'],
"wu_useropenid" => $user_info['openid'],
"wu_subcribetime" => date("Y-m-d H:i:s", $user_info['subscribe_time']),
"wu_subscribescene" => $user_info['subscribe_scene'],
"wu_nickname" => $user_info['nickname'],
"wu_sex" => $user_info['sex'],
"wu_language" => $user_info['language'],
"wu_country" => $user_info['country'],
"wu_province" => $user_info['province'],
"wu_city" => $user_info['city'],
"wu_headimg" => $user_info['headimgurl'],
"wu_unionid" => ($user_info['unionid'] ? $user_info['unionid'] : null)
);
$user_id = $this->Wechat_service_model->insert_wechat_user($user_column);
$user_column['wu_id'] = $user_id;
// new wechat customer
/**
* * 扫描带参数二维码关注的直接绑定
* * 给微信用户添加标签
*/
if ($coli_sn !== null) {
$customer_column = array(
"wc_wu_id" => $user_id, "wc_coli_sn" => $coli_sn, "wc_htordertype" => $order_type
);
$wc_id = $this->Wechat_service_model->insert_wechat_customer($customer_column);
// $access_token = $this->get_access_token(); // oe2BW1C9G-gmtDyOqwIvOMg8L_FA
$url = "/cgi-bin/tags/members/batchtagging";
$tag = array(
"openid_list" => array($user_info['openid']),
"tagid" => 101
);
$this->wechat_lib->call_wechat($this->wechat_host, $url, [], json_encode($tag, JSON_UNESCAPED_UNICODE));
// 推送已下单未支付
$pay_detail = $this->Order_model->order_info_to_pay($coli_sn);
$order = $this->Order_model->order_detail($coli_sn);
$order['wechat'] = array("wc_id" => $wc_id, "wu_id" => $user_id);
$this->wechat_lib->push_book_ok('trippest', $pay_detail['openid'], $order);
}
return $user_column;
}
private function scan_handle($input)
{
// 记录已关注扫描事件, 未绑定的增加绑定
$parse_source = explode('_', $input['EventKey']);
if (is_numeric($parse_source[0]) === true) {
$user_info = $this->Wechat_service_model->get_user(null, $this->wechat_config['app_id'], $input['FromUserName']);
$customer_column = array(
"wc_wu_id" => $user_info['wu_id'],
"wc_coli_sn" => $parse_source[0],
"wc_htordertype" => isset($parse_source[1]) ? $parse_source[1] : 27002
);
$wc_id = $this->Wechat_service_model->insert_wechat_customer($customer_column);
// 推送已下单未支付
$pay_detail = $this->Order_model->order_info_to_pay($parse_source[0]);
$order = $this->Order_model->order_detail($parse_source[0]);
if ( ! empty($order['orderTour'])) {
$order['wechat'] = array("wc_id" => $wc_id, "wu_id" => $user_info['wu_id']);
$this->wechat_lib->push_book_ok('trippest', $pay_detail['openid'], $order);
}
}
$this->wechat_lib->response_text();
return true;
}
private function text_handle($input)
{
$reply_content = $this->wechat_config['auto_reply']['reply_text'];
$this->wechat_lib->response_customer_service($reply_content, $input['FromUserName'], $this->wechat_operator);
$this->wechat_lib->send_text_customer($this->wechat_host, $input['FromUserName'], $reply_content);
// to customer service
$operator_mailbody = "<p> Dear : </p>" .
"<p>收到客人微信问询:<br /></p>" .
"<p>" . $input['Content'] ."</p>" .
"<p>发送时间:" . date("Y-m-d H:i:s", $input['CreateTime']) ."</p>";
$operator_mailbody .= "<p> 此邮件由系统自动发送, 请勿回复.</p>";
$this->Order_model->SendMail(
"chinahighlights",
"webform@chinahighlights.net",
"Niko",
"niko@trippest.com",
'#微信客人问询# TP公众号来客人啦快去看看哦 ' ,
$operator_mailbody);
return true;
}
public function convert_json_to_php()
{
$folder = FCPATH . 'bokun-product';
if (!is_dir($folder)) {
log_message('error', 'not found data dir');
echo "not found.";
return;
}
$files = array_values(array_diff(scandir($folder), array('.', '..')));
if (empty($files)) {
echo "none.";
return;
}
foreach ($files as $key => $json_file) {
$extension = strstr($json_file, ".");
if (strtolower($extension) !== ".json") {
continue;
}
$json = json_decode(file_get_contents($folder . "\\" . $json_file), true);
$this_file = fopen($folder . "\\" . strstr($json_file, ".", true) . ".php", "w+");
fwrite($this_file, "<?php\r\n" . '$data=' . var_export_min($json, 1) . ";");
fclose($this_file);
$json = null;
}
echo ("success");
return;
}
public function tour_data($city_name)
{
$data = null;
if ($city_name==='city-list') {
return $this->city_list();
}
include FCPATH . 'bokun-product' . "\\" . $city_name . ".php";
if (isset($data['items'])) {
array_walk($data['items'], function (&$item) {
$item['pricesByDateRange'] = $this->get_bokun_price($item['activity']['id']);
});
}
return $this->output->set_content_type('application/json')->set_output(json_encode($data));;
}
private function city_list()
{
$data = null;
include FCPATH . 'bokun-product\summary.php';
foreach ($data['top_list'] as $key => &$top) {
foreach ($top as $kt => &$vt) {
if ( ! empty($vt['sublist'])) {
foreach ($vt['sublist'] as $ks => &$vs) {
if (isset($data[$vs['id'] . '_code'])) {
$vs['items'] = $data[$vs['id'] . '_code'];
}
}
}
}
}
$ret = $data['top_list'];
// $ret['version'] = $data['version'];
return $this->output->set_content_type('application/json')->set_output(json_encode($ret));
}
public function get_bokun_price($bokun_activity_id = null)
{
$ret = null;
$today = time();
$folder = FCPATH . 'bokun-product\price';
$bokun_activity_id = $bokun_activity_id ? $bokun_activity_id : $this->input->get_post('activityId');
if (file_exists($folder . "\\" . $bokun_activity_id . ".php")) {
$data = null;
include FCPATH . 'bokun-product\price' . "\\" . $bokun_activity_id . ".php";
usort($data['pricesByDateRange'], function ($a, $b) {
return strtotime($a['from']) - strtotime($b['from']);
});
foreach ($data['pricesByDateRange'] as $key => $price_date) {
if (!isset($price_date['to'])) {
$price_date['to'] = strtotime("+10 days");
}
if ($today >= strtotime($price_date['from']) && $today <= strtotime($price_date['to'])) {
$ret = $price_date;
break;
}
}
}
if ($ret !== null) {
return $ret;
}
log_message('error', 'not found price data file. ' . $bokun_activity_id);
$price_list_arr = $this->get_product_price($bokun_activity_id);
foreach ($price_list_arr['pricesByDateRange'] as $key => $price_date) {
if (!isset($price_date['to'])) {
$price_date['to'] = strtotime("+10 days");
}
if ($today >= strtotime($price_date['from']) && $today <= strtotime($price_date['to'])) {
$ret = $price_date;
break;
}
}
return $ret;
}
/*!
* @Author: LYT: lyt@hainatravel.com
* @Date: 2019-11-07 14:11:52
* @Desc: 接收Bokun的推送
* * 推送请求示例:
* * GET
array (
'trigger' => 'PRODUCT_AVAILABILITY_UPDATE', // PRODUCT_INFO_UPDATE
'productCategory' => 'ACTIVITIES',
'productId' => '75348',
)
array (
'trigger' => 'PRODUCT_LIST_UPDATE',
'productListId' => '9880',
)
*/
public function bokun_notify()
{
$folder = FCPATH . 'bokun-product';
$input = $this->input->post() ? $this->input->post() : $this->input->get();
log_message('debug', 'bokun_notify' . PHP_EOL . var_export($input, 1));
$data = array();
include $folder . "\\" . "summary.php";
$data_summary = $data;
switch ($input['trigger']) {
case 'PRODUCT_LIST_UPDATE':
$list_id = $input['productListId'];
$data_summary = $data;
// 所有 product list 本身的信息, logo,cover等
$product_list = $this->bokun_lib->get_all_product_list();
$product_list_arr = json_decode($product_list, true);
$pick_flags = array_unique_fb(array_column($product_list_arr, 'flags'));
$list_flags = [];
foreach ($pick_flags as $key => $flag_arr) {
$list_flags = array_merge($list_flags, array_values($flag_arr));
}
$list_flags = array_filter(array_unique($list_flags));
$city_list_file = fopen($folder . "\\" . "city-list.php", "w+");
fwrite($city_list_file, "<?php\r\n" . '$data=' . var_export_min($product_list_arr, 1) . ";");
fclose($city_list_file);
// 生成摘要信息, 方便后续查询用
$list_id_title = array();
$data_summary['top_list'] = array();
$data_summary['version'] = date('YmdHi');
foreach ($list_flags as $key => $flag) {
foreach ($product_list_arr as $key => $list) {
$list_id_title[$list['id']] = mb_ereg_replace('[^a-zA-Z]', '', strtolower($list['title']));
if (in_array($flag,$list['flags']) ||
($flag==='Popular China Destinations' && empty($list['flags']))
) {
$temp = [];
foreach ($list['children'] as $kc => $vs) {
$temp[] = [ 'id' => $vs['id'], 'title' => $vs['title'], 'size'=>$vs['size'] ];
// sublist
$list_id_title[$vs['id']] = $vs['title'];
}
usort($temp, "Wechat_mp::sublists_order");
$data_summary['top_list'][$flag][] = [ 'id' => $list['id'], 'title' => $list_id_title[$list['id']], 'sublist' => $temp ];
}
}
}
$data_summary['list'] = $list_id_title;
// product list 包含的 product
$product_detail_arr = $this->save_product_list($list_id, $data_summary['list'][$list_id]);
// 生成摘要信息, 方便后续查询用
$this_list_items_id = array_map(function ($ele) {
return $ele['activity']['id'];
}, $product_detail_arr['items']);
$this_list_items_code = array_map(function ($ele) {
return $ele['activity']['externalId'];
}, $product_detail_arr['items']);
$data_summary[$list_id] = $this_list_items_id;
$data_summary[$list_id.'_code'] = $this_list_items_code;
$summary_file = fopen($folder . "\\" . "summary.php", "w+");
fwrite($summary_file, "<?php\r\n" . '$data=' . var_export_min($data_summary, 1) . ";");
fclose($summary_file);
break;
case 'PRODUCT_INFO_UPDATE':
$product_id = $input['productId'];
$product_list_id = null;
foreach ($data_summary as $ks => $vs) {
if ($ks === 'list') {
continue;
}
if (in_array($product_id, $vs)) {
$product_list_id = $ks;
break;
}
}
if ($product_list_id) {
$this->save_product_list($product_list_id, $data_summary['list'][$product_list_id]);
} else {
log_message('debug', 'no_found_product_list' . PHP_EOL . var_export($product_id, 1));
}
break;
case 'PRODUCT_AVAILABILITY_UPDATE':
$product_id = $input['productId'];
$this->get_product_price($product_id);
break;
default:
break;
}
return $this->output->set_content_type('application/json')->set_output(json_encode("OK"));
}
/**
* 自定义的排序sublists
*/
private function sublists_order($a, $b)
{
$orders = array(
'Day Trips',
'Day Tours',
'Great Wall Experience',
'Interesting Activities',
'Walking & Hiking Tours',
'Airport Transfer',
'Railway Station Transfer',
'Cruise Port Transfer',
'Shore Excursion',
'Shore Excursions',
'Multi Day Tours'
);
$a_index = array_search($a['title'], $orders);
$b_index = array_search($b['title'], $orders);
if ($a_index === $b_index) {
return 0;
}
return ($a_index < $b_index) ? -1 : 1;
}
private function save_product_list($list_id, $list_title)
{
if (!$this->bokun_lib) {
$this->load->library('Bokun_lib');
}
$folder = FCPATH . 'bokun-product';
$product_detail = $this->bokun_lib->get_product_list_detail($list_id);
$product_detail_arr = json_decode($product_detail, true);
$list_detail_file = fopen($folder . "\\" . $list_title . ".php", "w+");
fwrite($list_detail_file, "<?php\r\n" . '$data=' . var_export_min($product_detail_arr, 1) . ";");
fclose($list_detail_file);
return $product_detail_arr;
}
private function get_product_price($product_id)
{
$folder = FCPATH . 'bokun-product\price';
$price_list = $this->bokun_lib->get_activity_price($product_id);
$price_list_arr = json_decode($price_list, true);
if ($price_list_arr===null) {
$price_list_arr['pricesByDateRange'] = array();
return $price_list_arr;
}
usort($price_list_arr['pricesByDateRange'], function ($a, $b) {
return strtotime($a['from']) - strtotime($b['from']);
});
// if (isset($price_list_arr['pricesByDateRange'][0]['rates'][0]['passengers'][0]['tieredPrices'])) {
// array_walk_recursive($price_list_arr['pricesByDateRange'], function ()
// {
// });
// }
$this_file = fopen($folder . "\\" . $product_id . ".php", "w+");
fwrite($this_file, "<?php\r\n" . '$data=' . var_export_min($price_list_arr, 1) . ";");
fclose($this_file);
return $price_list_arr;
}
public function search_activity()
{
$text = $this->input->get_post('search');
$ret = $this->bokun_lib->search_by_text($text);
$data = array();
include FCPATH . 'bokun-product\summary.php';
array_walk($ret, 'Wechat_mp::get_tour_list_name', $data);
$ret = array_values(array_filter($ret, function ($ele)
{
return $ele->list_name !== '';
}));
return $this->output->set_content_type('application/json')->set_output(json_encode($ret));
}
private function get_tour_list_name(&$activity, $k, $data)
{
$list_ids = 0;
$activity->list_name = '';
foreach ($data as $key => $list) {
if ( ! is_array($list)) {
continue;
}
$search_id = array_search($activity->id, $list);
if ($search_id !== false) {
$list_ids = $key;
break;
}
}
if ($list_ids!==0) {
$activity->list_name = $data['list'][$list_ids];
}
}
}
/* End of file Wechat_mp.php */

@ -0,0 +1,384 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Wechat_order extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper('device');
$this->config->load("wechat", true);
$this->load->library('Wechat_lib');
$this->load->library('Paycenter_lib');
$this->load->model('Order_model');
$this->load->model('Wechat_service_model');
header('Access-Control-Allow-Origin:*');
// header('Access-Control-Allow-Origin:*');
// header('Access-Control-Allow-Methods:POST, GET');
// header('Access-Control-Max-Age:0');
// header('Access-Control-Allow-Headers:x-requested-with, Content-Type');
// header('Access-Control-Allow-Credentials:true');
}
public function index()
{ }
/**
* 生成带参数的公众号二维码
* @param str 订单主表key
* @param str 公众号的名字, 默认是Trippest.
* @return str 二维码图片地址
*/
public function order_qrcode($coli_sn, $wechat_host='trippest', $output=true)
{
$this->wechat_config = $this->config->item($wechat_host, 'wechat');
$this->wechat_host = $wechat_host;
$url = "/cgi-bin/qrcode/create";
$qrcode_request_info = array(
"action_name" => "QR_STR_SCENE",
"expire_seconds" => 604800,
"action_info" => array("scene" => array("scene_str" => strval($coli_sn)))
);
$qrcode_response_info = json_decode($this->wechat_lib->call_wechat($wechat_host, $url, [], json_encode($qrcode_request_info, JSON_UNESCAPED_UNICODE)), true);
$qrcode_src_url = $this->config->item('qrcode_src_prefix', 'wechat') . urlencode($qrcode_response_info['ticket']);
if ($output !== true) {
return $qrcode_src_url;
}
return $this->output->set_output($qrcode_src_url);
}
public function save()
{
$input = $this->input->post() ? $this->input->post() : $this->input->get();
// detect date if valid date
$input['start_date'] = true===validate_date($input['start_date']) ? $input['start_date'] : null;
$passenger = json_decode($input['passenger'], true);
$order_insert = array(); // BIZ_ConfirmLineInfo
$guest = array(); // BIZ_guest
$BPE_SN = array();
$book_detail = array(); // BIZ_ConfirmLineDetail
$pag_order = array(); // BIZ_PackageOrderInfo
$ht_pag_info = $this->Order_model->get_pag_tour_info($input['tour_external_id']);
/** BIZ_guest */
$guest['GUT_FirstName'] = $input['fullname'];
$guest['GUT_Email'] = $input['email'];
$guest['GUT_NationalityID'] = $input['country_id'];
$guest['GUT_Passport'] = $passenger[0]['idNumber'];
$guest['GUT_TEL'] = $guest['GUT_MoveTel'] = $input['mobile'];
$guest['GUT_POST'] = $input['country_code'];
$order_insert['COLI_GUT_SN'] = $this->Order_model->guest_save($guest);
/** BIZ_BookPeople */
foreach ($passenger as $kp => $passg) {
if ($passg['fullname'] === '' && $passg['idNumber'] === '') {
continue;
}
$book_people = array();
$book_people['BPE_FirstName'] = $passg['fullname'];
$book_people['BPE_GuestType'] = $passg['ageType'];
$book_people['BPE_Passport'] = $passg['idNumber'];
$book_people['BPE_PassportType'] = $passg['idType'];
$BPE_SN[] = $this->Order_model->book_people_save($book_people);
}
/** BIZ_ConfirmLineInfo */
$travelers = json_decode($input['travelers'], true);
$adult = $travelers['ADULT'] ? $travelers['ADULT'] : array_values($travelers[0]);
$child = isset($travelers['CHILD']) ? $travelers['CHILD'] : 0;
$baby = isset($travelers['INFANT']) ? $travelers['INFANT'] : 0;
$order_insert['COLI_State'] = 1;
$orderid_obj = $this->Order_model->biz_make_order_number();
$order_insert['COLI_ID'] = $orderid_obj->coli_id;
$order_insert['COLI_ApplyDate'] = date('Y-m-d H:i:s');
$order_insert['COLI_ConfirmType'] = '52002'; // 邮件
$order_insert['COLI_servicetype'] = 'D';
$order_insert['COLI_Currency'] = 'USD';
$order_insert['COLI_Department'] = $ht_pag_info['PAG_DEI_SN'];
$order_insert['COLI_SenderIP'] = $this->input->ip_address();
$order_insert['COLI_OrderDetailText'] = $this->parse_detail($input);
$order_insert['COLI_Price'] = $input['total_price'];
// $order_insert['COLI_Cost']
$order_insert['COLI_WebCode'] = $input['web_code'];
$order_insert['COLI_OriginalText'] = json_encode($input);
$order_insert['COLI_sourcetype'] = $ht_pag_info['sourcetype32'];
$order_insert['COLI_OrderSource'] = $this->device_code();
$coli_sn = $this->Order_model->order_save($order_insert);
$input['coli_sn'] = $coli_sn;
/** BIZ_ConfirmLineDetail */
$book_detail['COLD_COLI_SN'] = $coli_sn;
$book_detail['COLD_PlanVEI_SN'] = $ht_pag_info['PAG_DefaultVEI_SN'];
$book_detail['COLD_StartDate'] = date('Y-m-d', strtotime($input['start_date']));
// $book_detail['COLD_EndDate']
$book_detail['COLD_ServiceCity'] = $ht_pag_info['PAG_CII_SN'];
$book_detail['COLD_ServiceType'] = 'D';
$book_detail['COLD_ServiceSN'] = $ht_pag_info['PAG_SN'];
// $book_detail['COLD_ServiceSN2']
// $book_detail['COLD_TotalCost']
$book_detail['COLD_TotalPrice'] = $order_insert['COLI_Price'];
$book_detail['COLD_Count'] = 1;
$book_detail['COLD_PersonNum'] = $adult;
$book_detail['COLD_ChildNum'] = $child;
$book_detail['COLD_BabyNum'] = $baby;
$book_detail['COLD_State'] = 1;
// $book_detail['COLD_Memo']
// $book_detail['COLD_MemoText']
$cold_sn = $this->Order_model->book_detail_save($book_detail);
//订单客人列表
foreach ($BPE_SN as $bpe_item) {
$new_arr = array();
$new_arr = array("BPL_COLD_SN" => $cold_sn, "BPL_BPE_SN" => $bpe_item);
$this->Order_model->biz_bookpeople_List_save($new_arr);
}
/** BIZ_PackageOrderInfo */
$pickup = json_decode($input['pickup'], true);
$pag_order['POI_COLD_SN'] = $cold_sn;
// $pag_order['POI_FlightsNo']
// $pag_order['POI_AirPort']
// $pag_order['POI_Time']
$pag_order['POI_Hotel'] = $pickup['hotelName'];
$pag_order['POI_HotelAddress'] = $pickup['hotelAddress'] ? $pickup['hotelAddress'] : $pickup['pickupAddress'];
// $pag_order['POI_HotelPhone']
$pag_order['POI_HotelCheckInName'] = $pickup['checkInName'];
// $pag_order['POI_HotelCheckIn']
// $pag_order['POI_HotelCheckOut']
// $pag_order['POI_EndTime']
// $pag_order['POI_SelectOption']
$this->Order_model->pag_order_save($pag_order);
$input['coli_id'] = $order_insert['COLI_ID'];
$input['payment_now'] = 'true';
$input['paid'] = 'false';
$input['show_wxpay'] = $this->wechat_ua()===TRUE ? 'true' : 'false';
$input['order_qrcode'] = $this->order_qrcode($coli_sn, 'trippest', false);
$pay_param = array(
"order_id" => $order_insert['COLI_ID'] . "_B",
"lg" => "en_US",
"currency" => "USD",
"subject" => "Trippest-" . $order_insert['COLI_ID'],
"body" => "Trippest-" . $order_insert['COLI_ID'],
"total_amount" => $order_insert['COLI_Price'],
// "rmb_amount" => $order_insert['COLI_Price'],
"wx_account" => "trippest",
"return_url" => "https://www.trippest.com",
);
$input['payment_link'] = $this->paycenter_lib->create($pay_param);
$this->output->set_content_type('application/json')->set_output(json_encode($input));
// WeChat user
if (strval($input['userid']) !== '0') {
$customer_column = array(
"wc_wu_id" => $input['userid']
,"wc_coli_sn" => $coli_sn
,"wc_htordertype" => 27002
);
$wc_id = $this->Wechat_service_model->insert_wechat_customer($customer_column);
$input['wechat'] = array("wc_id" => $wc_id, "wu_id" => $input['userid']);
$this->push_order_book($input);
}
return false;
}
/*!
* @param array $order
*/
private function push_order_book($input)
{
$pay_detail = $this->Order_model->order_info_to_pay($input['coli_sn']);
$order = $this->Order_model->order_detail($input['coli_sn']);
$order['wechat'] = $input['wechat'];
$this->wechat_lib->push_book_ok('trippest', $pay_detail['openid'], $order);
return false;
}
/**
* 前端支付成功后, 查询支付结果
* * 确认成功: 推送
* * 失败: 无操作
*/
public function paid()
{
$input = $this->input->post() ? $this->input->post() : $this->input->get();
$coli_id = strstr($input['outTradeNo'], '_', true);
$payment = $this->wxpay_query($input['outTradeNo']);
if (empty($payment)) {
return $this->output->set_content_type('application/json')->set_output('{}');
}
$order = $this->Order_model->order_detail(0, $coli_id);
$wechat_order = $this->Wechat_service_model->get_customer($order['orderTour'][0]['coli']);
$order['wechat'] = array("wc_id" => $wechat_order['wc_id'], "wu_id" => $wechat_order['wc_wu_id']);
$this->wechat_lib->push_wechat_paid('trippest', $payment, $order);
$payment['paidQuote'] = $order['paidQuote'];
return $this->output->set_content_type('application/json')->set_output(json_encode($payment));
}
private function device_code()
{
$code = '62001';
switch (check_device()) {
case 'mobile':
$code = '62003';
break;
case 'tablet':
$code = '62002';
break;
default:
$code = '62001';
}
return $code;
}
private function parse_detail($input)
{
$orderdetail_text = '';
foreach ($input as $key => $value) {
switch ($key) {
case 'pickup':
$pickup_obj = json_decode($value, true);
$orderdetail_text .= "pickup option: " . $pickup_obj['value'] . PHP_EOL;
// $orderdetail_text .= "pickup option text: " . $pickup_obj['label'] . PHP_EOL;
$orderdetail_text .= "pickup address: " . $pickup_obj['pickupAddress'] . PHP_EOL;
break;
case 'passenger':
case 'web_code':
case 'country':
case 'country_id':
case 'country_code':
case 'travelers':
case 'adult_num':
case 'child_num':
case 'fullname':
case 'email':
case 'mobile':
case 'total_price':
break;
default:
$orderdetail_text .= str_replace("_", " ", $key) . ": " . $value . PHP_EOL;
break;
}
}
return $orderdetail_text;
}
/*!
* @Author: LYT: lyt@hainatravel.com
* @Date: 2019-11-13 16:48:27
* @Desc: 我的所有订单
*/
public function itinerary()
{
$ret = array("itineraryList" => array());
$wu_id = $this->input->get_post('userid');
if (!is_numeric($wu_id)) {
return $this->output->set_content_type('application/json')->set_output(json_encode($ret));
}
// $ret['userinfo'] = $this->Wechat_service_model->get_user($wu_id);
$ret['itineraryList'] = $this->Order_model->orders($wu_id);
array_walk($ret['itineraryList'], function (&$ele){$ele['startDate'] = date('M d, Y', strtotime($ele['startDate']));});
return $this->output->set_content_type('application/json')->set_output(json_encode($ret));
}
/*!
* @Author: LYT: lyt@hainatravel.com
* @Date: 2019-11-13 16:49:02
* @Desc: 订单预订详情
*/
public function detail($coli_sn=null)
{
$coli_sn = $coli_sn!==null ? $coli_sn : $this->input->get_post('coli');
$ret = $this->Order_model->order_detail($coli_sn);
return $this->output->set_content_type('application/json')->set_output(json_encode($ret));
}
/*!
* @Author: LYT: lyt@hainatravel.com
* @Date: 2019-11-13 16:49:11
* @Desc: 请求微信支付JSAPI所需的参数签名, 再次签名后返回前端发起支付
*/
public function wxpay_sign($wechat_host='trippest')
{
$GLOBALS['__WX_SITE_NAME__'] = $wechat_host;
bcscale(0);
$this->config->load('wechat', true);
$input = $this->input->post() ? $this->input->post() : $this->input->get();
if (false === $this->wechat_ua()) {
return $this->output->set_content_type('application/json')->set_output(json_encode(array()));
}
$pay_detail = $this->Order_model->order_info_to_pay($input['order_id']);
$this->load->library('wxpay/NativePay');
$wxfun = new WxPayUnifiedOrder();
$wxfun->SetBody("Trippest-" . $pay_detail['COLI_ID']);
$out_trade_no = $pay_detail['COLI_ID'] . "_B". rand(1000,9999);
$wxfun->SetOut_trade_no($out_trade_no);
// $wxfun->SetAttach(bcmul($pay_detail['cny_price'], $this->config->item('currency_unit', 'wechat'))); // test:
$wxfun->SetTotal_fee(bcmul($pay_detail['cny_price'], $this->config->item('currency_unit', 'wechat')));
// $wxfun->SetTotal_fee(1); // test:
$wxfun->SetTime_start(date("YmdHis"));
$wxfun->SetTime_expire(date("YmdHis", time() + 600));
// $wxfun->SetGoods_tag("test");
$wxfun->SetTrade_type("JSAPI");
$wxfun->SetOpenid($pay_detail['openid']);
// $wxfun->SetOpenid('oe2BW1C9G-gmtDyOqwIvOMg8L_FA'); // test:
$config = new WxPayConfig();
$order = WxPayApi::unifiedOrder($config, $wxfun);
// 生成预支付成功返回: $order
/*
{
"appid": "wx7e605820faf98a05",
"mch_id": "1528541381",
"nonce_str": "kD7nlZ1rsSvFzvM3",
"prepay_id": "wx08163228081581bac9a0e0ad1787454800",
"result_code": "SUCCESS",
"return_code": "SUCCESS",
"return_msg": "OK",
"sign": "11118EA80C2069F654B83991F682BD92423EFABA6064A82FF4A2763474B0FE3F",
"trade_type": "JSAPI"
}
*/
// 再次签名生成H5支付的参数
/*
$ret = array(
"appId" => "wx7e605820faf98a05",
"timeStamp" => time(),
"nonceStr" => $str,
"package" => "prepay_id=u802345jgfjsdfgsdg888",
"signType" => "MD5",
"paySign" => "C380BEC2BFD727A4B6845133519F3AD6"
);
*/
$tools = new JsApiPay();
$jsApiParameters = $tools->GetJsApiParameters($order);
$ret = array('param' => json_decode($jsApiParameters, true), 'order_no' => $out_trade_no);
return $this->output->set_content_type('application/json')->set_output(json_encode($ret));
}
private function wxpay_query($out_trade_no)
{
$GLOBALS['__WX_SITE_NAME__'] = 'trippest';
$this->load->library('wxpay/NativePay');
$input = new WxPayOrderQuery();
// $input->SetTransaction_id($transaction_id);
$input->SetOut_trade_no($out_trade_no);
$config = new WxPayConfig();
$ret = (WxPayApi::orderQuery($config, $input));
$ret = $ret['result_code']==='SUCCESS' ? $ret : array();
return $ret;
}
private function wechat_ua()
{
$ua = '';
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$ua = $_SERVER['HTTP_USER_AGENT'];
}
if (false === strstr(strtolower($ua), 'micromessenger')) {
return FALSE;
}
return TRUE;
}
}
/* End of file Wechat_order.php */

@ -0,0 +1,10 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

@ -0,0 +1,30 @@
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see http://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
echo "<pre>";
print_r ("output Test index");
echo "</pre>";
exit;
}
}
/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

@ -0,0 +1,10 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>404 Page Not Found</title>
<style type="text/css">
::selection{ background-color: #E13300; color: white; }
::moz-selection{ background-color: #E13300; color: white; }
::webkit-selection{ background-color: #E13300; color: white; }
body {
background-color: #fff;
margin: 40px;
font: 13px/20px normal Helvetica, Arial, sans-serif;
color: #4F5155;
}
a {
color: #003399;
background-color: transparent;
font-weight: normal;
}
h1 {
color: #444;
background-color: transparent;
border-bottom: 1px solid #D0D0D0;
font-size: 19px;
font-weight: normal;
margin: 0 0 14px 0;
padding: 14px 15px 10px 15px;
}
code {
font-family: Consolas, Monaco, Courier New, Courier, monospace;
font-size: 12px;
background-color: #f9f9f9;
border: 1px solid #D0D0D0;
color: #002166;
display: block;
margin: 14px 0 14px 0;
padding: 12px 10px 12px 10px;
}
#container {
margin: 10px;
border: 1px solid #D0D0D0;
-webkit-box-shadow: 0 0 8px #D0D0D0;
}
p {
margin: 12px 15px 12px 15px;
}
</style>
</head>
<body>
<div id="container">
<h1><?php echo $heading; ?></h1>
<?php echo $message; ?>
</div>
</body>
</html>

@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Database Error</title>
<style type="text/css">
::selection{ background-color: #E13300; color: white; }
::moz-selection{ background-color: #E13300; color: white; }
::webkit-selection{ background-color: #E13300; color: white; }
body {
background-color: #fff;
margin: 40px;
font: 13px/20px normal Helvetica, Arial, sans-serif;
color: #4F5155;
}
a {
color: #003399;
background-color: transparent;
font-weight: normal;
}
h1 {
color: #444;
background-color: transparent;
border-bottom: 1px solid #D0D0D0;
font-size: 19px;
font-weight: normal;
margin: 0 0 14px 0;
padding: 14px 15px 10px 15px;
}
code {
font-family: Consolas, Monaco, Courier New, Courier, monospace;
font-size: 12px;
background-color: #f9f9f9;
border: 1px solid #D0D0D0;
color: #002166;
display: block;
margin: 14px 0 14px 0;
padding: 12px 10px 12px 10px;
}
#container {
margin: 10px;
border: 1px solid #D0D0D0;
-webkit-box-shadow: 0 0 8px #D0D0D0;
}
p {
margin: 12px 15px 12px 15px;
}
</style>
</head>
<body>
<div id="container">
<h1><?php echo $heading; ?></h1>
<?php echo $message; ?>
</div>
</body>
</html>

@ -0,0 +1,62 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Error</title>
<style type="text/css">
::selection{ background-color: #E13300; color: white; }
::moz-selection{ background-color: #E13300; color: white; }
::webkit-selection{ background-color: #E13300; color: white; }
body {
background-color: #fff;
margin: 40px;
font: 13px/20px normal Helvetica, Arial, sans-serif;
color: #4F5155;
}
a {
color: #003399;
background-color: transparent;
font-weight: normal;
}
h1 {
color: #444;
background-color: transparent;
border-bottom: 1px solid #D0D0D0;
font-size: 19px;
font-weight: normal;
margin: 0 0 14px 0;
padding: 14px 15px 10px 15px;
}
code {
font-family: Consolas, Monaco, Courier New, Courier, monospace;
font-size: 12px;
background-color: #f9f9f9;
border: 1px solid #D0D0D0;
color: #002166;
display: block;
margin: 14px 0 14px 0;
padding: 12px 10px 12px 10px;
}
#container {
margin: 10px;
border: 1px solid #D0D0D0;
-webkit-box-shadow: 0 0 8px #D0D0D0;
}
p {
margin: 12px 15px 12px 15px;
}
</style>
</head>
<body>
<div id="container">
<h1><?php echo $heading; ?></h1>
<?php echo $message; ?>
</div>
</body>
</html>

@ -0,0 +1,10 @@
<div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
<h4>A PHP Error was encountered</h4>
<p>Severity: <?php echo $severity; ?></p>
<p>Message: <?php echo $message; ?></p>
<p>Filename: <?php echo $filepath; ?></p>
<p>Line Number: <?php echo $line; ?></p>
</div>

@ -0,0 +1,10 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

@ -0,0 +1,73 @@
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
function check_device()
{
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$ua = $_SERVER['HTTP_USER_AGENT'];
} else {
$ua = '';
}
## This credit must stay intact (Unless you have a deal with @lukasmig or frimerlukas@gmail.com
## Made by Lukas Frimer Tholander from Made In Osted Webdesign.
## Price will be $2
$iphone = strstr(strtolower($ua), 'mobile'); //Search for 'mobile' in user-agent (iPhone have that)
$android = strstr(strtolower($ua), 'android'); //Search for 'android' in user-agent
$windowsPhone = strstr(strtolower($ua), 'phone'); //Search for 'phone' in user-agent (Windows Phone uses that)
if (!function_exists('androidTablet')) {
function androidTablet($ua)
{ //Find out if it is a tablet
if (strstr(strtolower($ua), 'android')) { //Search for android in user-agent
if (!strstr(strtolower($ua), 'mobile')) { //If there is no ''mobile' in user-agent (Android have that on their phones, but not tablets)
return true;
}
}
}
}
$androidTablet = androidTablet($ua); //Do androidTablet function
$ipad = strstr(strtolower($ua), 'ipad'); //Search for iPad in user-agent
if ($androidTablet || $ipad) { //If it's a tablet (iPad / Android)
return 'tablet';
} elseif ($iphone && !$ipad || $android && !$androidTablet || $windowsPhone) { //If it's a phone and NOT a tablet
return 'mobile';
} else { //If it's not a mobile device
return 'desktop';
}
}
function validate_date($date)
{
$d = DateTime::createFromFormat('Y-m-d', $date);
$d2 = DateTime::createFromFormat('Y/n/d', $date);
$d3 = DateTime::createFromFormat('n/d/Y', $date);
// The Y ( 4 digits year ) returns TRUE for any integer with any number of digits so changing the comparison from == to === fixes the issue.
// return $d && $d->format($format) === $date;
return $d || $d2 || $d3;
}
function array_unique_fb($array2D)
{
$temp = [];
foreach ($array2D as $v) {
$v = join(",", $v); //降维,也可以用implode,将一维数组转换为用逗号连接的字符串
$temp[] = $v;
}
$temp = array_unique($temp); //去掉重复的字符串,也就是重复的一维数组
foreach ($temp as $k => $v) {
$temp[$k] = explode(",", $v); //再将拆开的数组重新组装
}
return $temp;
}
function var_export_min($var, $return = false) {
if (is_array($var)) {
$toImplode = array();
foreach ($var as $key => $value) {
$toImplode[] = var_export($key, true).'=>'.var_export_min($value, true);
}
$code = 'array('.implode(',', $toImplode).')';
if ($return) return $code;
else echo $code;
} else {
return var_export($var, $return);
}
}

@ -0,0 +1,10 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

@ -0,0 +1,10 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

@ -0,0 +1,10 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

@ -0,0 +1,10 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

@ -0,0 +1,10 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

@ -0,0 +1,105 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Bokun_lib
{
protected $ci;
private $bokun_url = 'https://api.bokun.is'; // https://api.bokun.io
private $access_key = '2f6284e43ee84f6a85fbb0c5660c7404';
private $secret_key = 'ef3353fe28dc402b9045c2a766b68efe';
public function __construct()
{
$this->ci = &get_instance();
}
public function get_all_product_list()
{
$path = "/product-list.json/list?lang=EN";
$product_list = $this->call_bokun($path, 'get');
return ($product_list);
}
public function get_product_list_detail($list_id)
{
$path = "/product-list.json/$list_id?currency=USD&lang=EN";
$product_list = $this->call_bokun($path, 'get');
return ($product_list);
}
public function get_activity_price($bokun_id)
{
$path = "/activity.json/$bokun_id/price-list?currency=USD";
$price_list = $this->call_bokun($path, 'get');
return ($price_list);
}
public function search_by_text($text)
{
$path = "/activity.json/search?currency=USD&lang=EN";
$request_body = array(
"textFilter" => array(
"operator" => "and",
"searchExternalId" => true,
"searchFullText" => false,
"searchKeywords" => true,
"searchTitle" => true,
"text" => $text,
"wildcard" => false
)
);
$result = $this->call_bokun($path, 'post', json_encode($request_body, JSON_UNESCAPED_UNICODE));
return json_decode($result)->items;
}
private function make_bokun_signature($date, $method, $path)
{
$raw_str = $date . $this->access_key . strtoupper($method) . $path;
return base64_encode(hash_hmac("sha1", $raw_str, $this->secret_key, TRUE));
}
private function call_bokun($path, $method, $body = null)
{
$url = $this->bokun_url . $path;
$create_date = gmdate("Y-m-d H:i:s");
$bokun_signature = $this->make_bokun_signature($create_date, $method, $path);
$curl = curl_init();
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 20);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_URL, $url);
$http_header = array(
"X-Bokun-Date:" . $create_date,
"X-Bokun-AccessKey :" . $this->access_key,
"X-Bokun-Signature :" . $bokun_signature
);
$set_post = strtoupper($method) === 'GET' ? false : true;
curl_setopt($curl, CURLOPT_POST, $set_post);
if ($body !== null) {
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
$http_header[] = 'Content-Type: application/json';
}
curl_setopt($curl, CURLOPT_HTTPHEADER, $http_header);
log_message('debug', 'call_bokun ' . $method . PHP_EOL . var_export($url, 1));
$output = curl_exec($curl);
if (curl_errno($curl)) {
log_message('error', "curl error code: " . curl_error($curl) . "; curl call: " . $path);
} else {
$httpStatusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if (200 !== $httpStatusCode) {
log_message('error', "Request html Status Code: " . $httpStatusCode . "; curl call: " . $path);
}
}
curl_close($curl);
return $output;
}
}
/* End of file Bokun_lib.php */

@ -0,0 +1,40 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Order_lib
{
protected $ci;
public function __construct()
{
$this->ci =& get_instance();
}
/*!
* @Author: LYT: lyt@hainatravel.com
* @Date: 2019-11-13 16:52:38
* @Desc: 客户角度的订单流程
* * 提交成功>等待支付>支付成功>联络客户>预订审核确认>地接安排>地接确认
* * 取消; 不成行
*/
public function order_step($current, $ifpaid)
{
$ret = array(
"s1" => array( "name" => "Booking success"),
"s2" => array( "name" => "Waiting for payment"),
"s3" => array( "name" => "Payment success"),
"s4" => array( "name" => "Waiting for confirmation"),
"s5" => array( "name" => "Booking confirmed"),
"s6" => array( "name" => "Local arrangements are in process"),
"s7" => array( "name" => "Local arrangements consfirmed"),
);
$cancel = array( "name" => "Booking canceled");
}
}
/* End of file Order_lib.php */

@ -0,0 +1,39 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Paycenter_lib
{
protected $ci;
protected $key = '7a46484300f04031b42fdd44559578e4';
protected $domain = 'https://secure.chinahighlights.com/pay/paymentservice/?';
// https://secure.chinahighlights.com/pay/paymentservice/?b3JkZXJfaWQ9MTUwNDE0NzIwM19UJnN1YmplY3Q9MTUwNDE0NzIwM19UJnRvdGFsX2Ftb3VudD0xNTAmY3VycmVuY3k9U0dEJmxnPWVuX1VTJnJtYl9hbW91bnQ9NzM2LjUmd3hfYWNjb3VudD1jaHQmc2lnbj04RUI5RTJFOTAyNUM0Mzg1MEYxQzU1ODk1Q0ZBRTA5QiZib2R5PVRyYWNraW5nIENvZGU6DQpUcmF2ZWwgQWR2aXNvcjoNCkNvbnRlbnQ6
public function __construct()
{
$this->ci =& get_instance();
}
public function create($arr)
{
$arr['sign'] = $this->make_sign($arr);
$query_str = http_build_query($arr);
return $this->domain . base64_encode($query_str);
}
private function make_sign($arr)
{
$raw = "currency=" . strtoupper($arr['currency']);
$raw .= "&order_id=" . $arr['order_id'];
$raw .= "&rmb_amount=" . $arr['rmb_amount'];
$raw .= "&total_amount=" . $arr['total_amount'];
$raw .= "&key=" . $this->key;
$sign = md5($raw);
return $sign;
}
}
/* End of file Paycenter.php */

@ -0,0 +1,404 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Wechat_lib
{
protected $ci;
private $wechat_config;
private $wechat_host;
public function __construct()
{
$this->ci =& get_instance();
$this->ci->config->load("wechat", true);
}
public function response_to_wx($response_arr=null)
{
if ($response_arr===null) {
echo "";
}
$response_body = $this->to_xml($response_arr);
echo $response_body;
return false;
}
/**
* 转发到微信客服
* @param string $text
* @param string $to_user
* @param string $from_operator
*/
public function response_customer_service($text=null, $to_user=null, $from_operator=null)
{
$content_arr = $text===null ? null :
array(
"ToUserName" => $to_user,
"FromUserName" => $from_operator,
"CreateTime" => time(),
"MsgType" => "transfer_customer_service",
"Content" => $text
);
return $this->response_to_wx($content_arr);
}
public function response_text($text=null, $to_user=null, $from_operator=null)
{
$content_arr = $text===null ? null :
array(
"ToUserName" => $to_user,
"FromUserName" => $from_operator,
"CreateTime" => time(),
"MsgType" => "text",
"Content" => $text
);
return $this->response_to_wx($content_arr);
}
/**
* 开发者认证token
* @param array $input:微信的GET请求数据
*/
public function auth_signature($input, $token)
{
$s = $input["signature"];
$t = $input["timestamp"];
$n = $input["nonce"];
$e = $input["echostr"];
$tmpArr = array($t, $n, $token);
sort($tmpArr, SORT_STRING);
$tmpStr = implode( $tmpArr );
$tmpStr = sha1( $tmpStr );
// $ee = 'V3xwtddYXPES064KgVh0uxqfPVV2qDK1HvfX7PIRvxR';
ob_clean();
if( $s == $tmpStr ){
echo $e;
}else{
echo "";
}
return false;
}
public function call_wechat($wechat_host, $url, $get_data=array(), $post_data=null)
{
$this->wechat_host = $wechat_host;
$this->wechat_config = $this->ci->config->item($wechat_host, 'wechat');
if ( false === array_key_exists('code', $get_data)) {
$access_token = $this->get_access_token();
$get_data = array_merge($get_data, array("access_token" => $access_token) );
}
$url = $this->ci->config->item('url_domain', 'wechat') . $url . "?" . http_build_query($get_data);
$curl = curl_init();
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 20);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_URL, $url);
if ($post_data !== null) {
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
}
$output = curl_exec($curl);
if (curl_errno($curl)) {
log_message('error', "curl error code: ".curl_error($curl)."; curl postBodyString: ".$post_data);
} else {
$httpStatusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if (200 !== $httpStatusCode) {
log_message('error', "Request html Status Code: ".$httpStatusCode."; curl postBodyString: ".$post_data);
}
$output_arr = json_decode($output, true);
if (false !== stripos($output, "errcode")
&& 0 !== intval($output_arr['errcode'])
) {
log_message('error','wechat reponse error:' . var_export($output, 1));
curl_close($curl);
return null;
}
}
curl_close($curl);
return $output;
}
private function get_access_token()
{
$url = $this->ci->config->item('url_domain', 'wechat') . "/cgi-bin/token?grant_type=client_credential&appid=" . $this->wechat_config['app_id'] . "&secret=" . $this->wechat_config['app_secret'];
$curl = curl_init();
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 20);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_URL, $url);
$output = curl_exec($curl);
if (curl_errno($curl)) {
log_message('error', "curl error code: ".curl_error($curl));
} else {
$httpStatusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if (200 !== $httpStatusCode) {
log_message('error', "Request html Status Code: ".$httpStatusCode);
}
$output_arr = json_decode($output, true);
if (false !== stripos($output, "errcode")
&& 0 !== intval($output_arr['errcode'])
) {
log_message('error','wechat reponse error:' . var_export($output, 1));
curl_close($curl);
return null;
}
}
curl_close($curl);
$access_token_arr = json_decode($output, true);
return $access_token_arr['access_token'];
}
/**
* 发送文本消息给已关注用户
* 当用户和公众号产生特定动作的交互时, 允许在48小时内调用此接口发送消息给用户
* 允许的<特定动作>
* * 用户发送信息
* * 点击自定义菜单仅有点击推事件、扫码推事件、扫码推事件且弹出“消息接收中”提示框这3种菜单类型是会触发客服接口的
* * 关注公众号
* * 扫描二维码
* * 支付成功
* * 用户维权
* @param [type] $wechat_host
* @param 用户openid $to_user
* @param 文本内容 $text
*/
public function send_text_customer($wechat_host, $to_user, $text)
{
$url = "/cgi-bin/message/custom/send";
$post = array(
"touser" => $to_user,
"msgtype" => "text",
"text" => array(
"content" => $text
)
);
return $this->call_wechat($wechat_host, $url, [], json_encode($post, JSON_UNESCAPED_UNICODE));
}
/**
* 已下单未支付
* @param [type] $wechat_host
* @param [type] $openid
* @param array $order
*/
public function push_book_ok($wechat_host, $openid, $order=array())
{
$this->ci->load->model('Wechat_service_model');
$url = "/cgi-bin/message/template/send";
$order_detail_path = "/order" . "/" .$order['orderTour'][0]['coli'] . "/" . $order['orderTour'][0]['orderId'];
$post = array(
"touser" => $openid,
"template_id" => 'eSnnOFczriQFJSPy4q7797iKi4HCh6im5vP8iLlIHAU',
"url" => 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7e605820faf98a05&redirect_uri=http%3A%2F%2Ftrippest.mycht.cn%2Fapi%2Findex.php%2Fwechat-mp%2Flogin-now%2Ftrippest%3Fl%3D' . urlencode($order_detail_path) . '&response_type=code&scope=snsapi_base&state=detail#wechat_redirect',
"topcolor" => '#173177',
"data" => array(
"first" => array(
"value" => 'Thanks for booking with Trippest. Click to follow up the payment now.',
"color" => '#173177'
),
"OrderID" => array(
"value" => 'Booking Reference # ' . $order['orderTour'][0]['orderId'],
"color" => '#173177'
),
"PkgName" => array(
"value" => $order['orderTour'][0]['tourName'],
"color" => '#173177'
),
"TakeOffDate" => array(
"value" => 'Tour Date ' . date('M.d, Y', strtotime($order['orderTour'][0]['startDate'])),
"color" => '#173177'
),
"Remark" => array(
"value" => 'For more information…',
"color" => '#173177'
)
),
);
$this->call_wechat($wechat_host, $url, [], json_encode($post, JSON_UNESCAPED_UNICODE));
$push_arr = array(
"wp_wu_id" => $order['wechat']['wu_id'],
"wp_msgtype" => "template",
"wp_content" => json_encode($post['data'], JSON_UNESCAPED_UNICODE),
"wp_templateid" => $post['template_id'],
"wp_templatename" => "旅游订单待支付",
"wp_createtime" => date('Y-m-d H:i:s'),
"wp_wc_id" => $order['wechat']['wc_id']
);
$this->ci->Wechat_service_model->insert_wechat_push($push_arr);
return true;
}
/**
* 行程即将开始
* 导游司机等调度信息
* @param [type] $wechat_host
* @param [type] $openid
* @param array $order
*/
public function push_arrangement($wechat_host, $openid, $order=array())
{
$this->ci->load->model('Wechat_service_model');
$url = "/cgi-bin/message/template/send";
$order_detail_path = "/order" . "/" .$order['orderTour'][0]['coli'] . "/" . $order['orderTour'][0]['orderId'];
$post = array(
"touser" => $openid,
"template_id" => 'wqfkOjDe5VpJn1hYC2lhO3w2qQ96o-a1ylt0wl9-1JE',
"url" => 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7e605820faf98a05&redirect_uri=http%3A%2F%2Ftrippest.mycht.cn%2Fapi%2Findex.php%2Fwechat-mp%2Flogin-now%2Ftrippest%3Fl%3D' . urlencode($order_detail_path) . '&response_type=code&scope=snsapi_base&state=detail#wechat_redirect',
"topcolor" => '#173177',
"data" => array(
"first" => array(
"value" => 'Booking Reference # ' . $order['orderTour'][0]['orderId'],
"color" => '#173177'
),
"keyword1" => array(
"value" => $order['orderTour'][0]['tourName'],
"color" => '#173177'
),
"keyword2" => array(
"value" => 'Start Date: ' . $order['orderTour'][0]['startDate'],
"color" => '#173177'
),
"remark" => array(
"value" => 'Tap this card to find more details.', // TODO: Guide:北京禹昭Helen, Mobile:15333241912
"color" => '#173177'
)
),
);
$this->call_wechat($wechat_host, $url, [], json_encode($post, JSON_UNESCAPED_UNICODE));
$push_arr = array(
"wp_wu_id" => $order['wechat']['wu_id'],
"wp_msgtype" => "template",
"wp_content" => json_encode($post['data'], JSON_UNESCAPED_UNICODE),
"wp_templateid" => $post['template_id'],
"wp_templatename" => "行程即将开始",
"wp_createtime" => date('Y-m-d H:i:s'),
"wp_wc_id" => $order['wechat']['wc_id']
);
$this->ci->Wechat_service_model->insert_wechat_push($push_arr);
return true;
}
public function push_wechat_paid($wechat_host, $payment=array(), $order=array() )
{
$this->ci->load->model('Wechat_service_model');
$url = "/cgi-bin/message/template/send";
$order_detail_path = "/order" . "/" .$order['orderTour'][0]['coli'] . "/" . $order['orderTour'][0]['orderId'];
bcscale(2);
$total_fee = bcdiv($payment['total_fee'], $this->ci->config->item('currency_unit', 'wechat'));
$post = array(
"touser" => $payment['openid'],
"template_id" => '2ar2YEdmcylhGJr2e6C9SLresnCWMLfDK8RPr2caj04',
"url" => 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7e605820faf98a05&redirect_uri=http%3A%2F%2Ftrippest.mycht.cn%2Fapi%2Findex.php%2Fwechat-mp%2Flogin-now%2Ftrippest%3Fl%3D' . urlencode($order_detail_path) . '&response_type=code&scope=snsapi_base&state=detail#wechat_redirect',
"topcolor" => '#173177',
"data" => array(
"first" => array(
"value" => 'Payment successful and your booking is confirmed.',
"color" => '#173177'
),
"keyword1" => array(
"value" => $order['orderTour'][0]['leader'],
"color" => '#173177'
),
"keyword2" => array(
"value" => 'BR# ' . $order['orderTour'][0]['orderId'],
"color" => '#173177'
),
"keyword3" => array(
"value" => 'Total payment ' . $payment['fee_type'] . $total_fee,
"color" => '#173177'
),
"keyword4" => array(
"value" => $order['orderTour'][0]['tourName'],
"color" => '#173177'
),
"remark" => array(
"value" => 'Youll receive a notice about guides/driver info at the night before tour started.',
"color" => '#173177'
)
),
);
$this->call_wechat($wechat_host, $url, [], json_encode($post, JSON_UNESCAPED_UNICODE));
$push_arr = array(
"wp_wu_id" => $order['wechat']['wu_id'],
"wp_msgtype" => "template",
"wp_content" => json_encode($post['data'], JSON_UNESCAPED_UNICODE),
"wp_templateid" => $post['template_id'],
"wp_templatename" => "支付成功",
"wp_createtime" => date('Y-m-d H:i:s'),
"wp_wc_id" => $order['wechat']['wc_id']
);
$this->ci->Wechat_service_model->insert_wechat_push($push_arr);
return true;
}
/**
* 格式化参数格式化成url参数
*/
public function to_url_params($xml_arr)
{
$buff = "";
foreach ($xml_arr as $k => $v)
{
if($k != "sign" && $v != "" && !is_array($v)){
$buff .= $k . "=" . $v . "&";
}
}
$buff = trim($buff, "&");
return $buff;
}
/**
* 输出xml字符
* @throws WxPayException
**/
function to_xml($arr)
{
if(!is_array($arr) || count($arr) <= 0)
{
return false;
}
$xml = "<xml>";
foreach ($arr as $key=>$val)
{
if (is_numeric($val)){
$xml.="<".$key.">".$val."</".$key.">";
}else{
$xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
}
}
$xml.="</xml>";
return $xml;
}
/**
* 将xml转为array
* @param string $xml
* @throws WxPayException
*/
function from_xml($xml)
{
if(!$xml){
return false;
}
//将XML转为array
//禁止引用外部xml实体
libxml_disable_entity_loader(true);
return json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
}
}
/* End of file Wechat_lib.php */

@ -0,0 +1,10 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

@ -0,0 +1,4 @@
注意事项:
1.WXBizMsgCrypt.php文件提供了WXBizMsgCrypt类的实现是用户接入企业微信的接口类。Sample.php提供了示例以供开发者参考。errorCode.php, pkcs7Encoder.php, sha1.php, xmlparse.php文件是实现这个类的辅助类开发者无须关心其具体实现。
2.WXBizMsgCrypt类封装了 DecryptMsg, EncryptMsg两个接口分别用于开发者解密以及开发者回复消息的加密。使用方法可以参考Sample.php文件。
3.加解密协议请参考微信公众平台官方文档。

@ -0,0 +1,40 @@
<?php
include_once "wxBizMsgCrypt.php";
// 第三方发送消息给公众平台
$encodingAesKey = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG";
$token = "pamtest";
$timeStamp = "1409304348";
$nonce = "xxxxxx";
$appId = "wxb11529c136998cb6";
$text = "<xml><ToUserName><![CDATA[oia2Tj我是中文jewbmiOUlr6X-1crbLOvLw]]></ToUserName><FromUserName><![CDATA[gh_7f083739789a]]></FromUserName><CreateTime>1407743423</CreateTime><MsgType><![CDATA[video]]></MsgType><Video><MediaId><![CDATA[eYJ1MbwPRJtOvIEabaxHs7TX2D-HV71s79GUxqdUkjm6Gs2Ed1KF3ulAOA9H1xG0]]></MediaId><Title><![CDATA[testCallBackReplyVideo]]></Title><Description><![CDATA[testCallBackReplyVideo]]></Description></Video></xml>";
$pc = new WXBizMsgCrypt($token, $encodingAesKey, $appId);
$encryptMsg = '';
$errCode = $pc->encryptMsg($text, $timeStamp, $nonce, $encryptMsg);
if ($errCode == 0) {
print("加密后: " . $encryptMsg . "\n");
} else {
print($errCode . "\n");
}
$xml_tree = new DOMDocument();
$xml_tree->loadXML($encryptMsg);
$array_e = $xml_tree->getElementsByTagName('Encrypt');
$array_s = $xml_tree->getElementsByTagName('MsgSignature');
$encrypt = $array_e->item(0)->nodeValue;
$msg_sign = $array_s->item(0)->nodeValue;
$format = "<xml><ToUserName><![CDATA[toUser]]></ToUserName><Encrypt><![CDATA[%s]]></Encrypt></xml>";
$from_xml = sprintf($format, $encrypt);
// 第三方收到公众号平台发送的消息
$msg = '';
$errCode = $pc->decryptMsg($msg_sign, $timeStamp, $nonce, $from_xml, $msg);
if ($errCode == 0) {
print("解密后: " . $msg . "\n");
} else {
print($errCode . "\n");
}

@ -0,0 +1,35 @@
<?php
/**
* error code 说明.
* <ul>
* <li>-40001: 签名验证错误</li>
* <li>-40002: xml解析失败</li>
* <li>-40003: sha加密生成签名失败</li>
* <li>-40004: encodingAesKey 非法</li>
* <li>-40005: appid 校验错误</li>
* <li>-40006: aes 加密失败</li>
* <li>-40007: aes 解密失败</li>
* <li>-40008: 解密后得到的buffer非法</li>
* <li>-40009: base64加密失败</li>
* <li>-40010: base64解密失败</li>
* <li>-40011: 生成xml失败</li>
* </ul>
*/
class ErrorCode
{
public static $OK = 0;
public static $ValidateSignatureError = -40001;
public static $ParseXmlError = -40002;
public static $ComputeSignatureError = -40003;
public static $IllegalAesKey = -40004;
public static $ValidateAppidError = -40005;
public static $EncryptAESError = -40006;
public static $DecryptAESError = -40007;
public static $IllegalBuffer = -40008;
public static $EncodeBase64Error = -40009;
public static $DecodeBase64Error = -40010;
public static $GenReturnXmlError = -40011;
}
?>

@ -0,0 +1,167 @@
<?php
include_once "errorCode.php";
/**
* PKCS7Encoder class
*
* 提供基于PKCS7算法的加解密接口.
*/
class PKCS7Encoder
{
public static $block_size = 32;
/**
* 对需要加密的明文进行填充补位
* @param $text 需要进行填充补位操作的明文
* @return 补齐明文字符串
*/
function encode($text)
{
$block_size = PKCS7Encoder::$block_size;
$text_length = strlen($text);
//计算需要填充的位数
$amount_to_pad = PKCS7Encoder::$block_size - ($text_length % PKCS7Encoder::$block_size);
if ($amount_to_pad == 0) {
$amount_to_pad = PKCS7Encoder::block_size;
}
//获得补位所用的字符
$pad_chr = chr($amount_to_pad);
$tmp = "";
for ($index = 0; $index < $amount_to_pad; $index++) {
$tmp .= $pad_chr;
}
return $text . $tmp;
}
/**
* 对解密后的明文进行补位删除
* @param decrypted 解密后的明文
* @return 删除填充补位后的明文
*/
function decode($text)
{
$pad = ord(substr($text, -1));
if ($pad < 1 || $pad > 32) {
$pad = 0;
}
return substr($text, 0, (strlen($text) - $pad));
}
}
/**
* Prpcrypt class
*
* 提供接收和推送给公众平台消息的加解密接口.
*/
class Prpcrypt
{
public $key;
function Prpcrypt($k)
{
$this->key = base64_decode($k . "=");
}
/**
* 对明文进行加密
* @param string $text 需要加密的明文
* @return string 加密后的密文
*/
public function encrypt($text, $appid)
{
try {
//获得16位随机字符串填充到明文之前
$random = $this->getRandomStr();
$text = $random . pack("N", strlen($text)) . $text . $appid;
// 网络字节序
$size = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
$iv = substr($this->key, 0, 16);
//使用自定义的填充方式对明文进行补位填充
$pkc_encoder = new PKCS7Encoder;
$text = $pkc_encoder->encode($text);
mcrypt_generic_init($module, $this->key, $iv);
//加密
$encrypted = mcrypt_generic($module, $text);
mcrypt_generic_deinit($module);
mcrypt_module_close($module);
//print(base64_encode($encrypted));
//使用BASE64对加密后的字符串进行编码
return array(ErrorCode::$OK, base64_encode($encrypted));
} catch (Exception $e) {
//print $e;
return array(ErrorCode::$EncryptAESError, null);
}
}
/**
* 对密文进行解密
* @param string $encrypted 需要解密的密文
* @return string 解密得到的明文
*/
public function decrypt($encrypted, $appid)
{
try {
//使用BASE64对需要解密的字符串进行解码
$ciphertext_dec = base64_decode($encrypted);
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, '');
$iv = substr($this->key, 0, 16);
mcrypt_generic_init($module, $this->key, $iv);
//解密
$decrypted = mdecrypt_generic($module, $ciphertext_dec);
mcrypt_generic_deinit($module);
mcrypt_module_close($module);
} catch (Exception $e) {
return array(ErrorCode::$DecryptAESError, null);
}
try {
//去除补位字符
$pkc_encoder = new PKCS7Encoder;
$result = $pkc_encoder->decode($decrypted);
//去除16位随机字符串,网络字节序和AppId
if (strlen($result) < 16)
return "";
$content = substr($result, 16, strlen($result));
$len_list = unpack("N", substr($content, 0, 4));
$xml_len = $len_list[1];
$xml_content = substr($content, 4, $xml_len);
$from_appid = substr($content, $xml_len + 4);
} catch (Exception $e) {
//print $e;
return array(ErrorCode::$IllegalBuffer, null);
}
if ($from_appid != $appid)
return array(ErrorCode::$ValidateAppidError, null);
return array(0, $xml_content);
}
/**
* 随机生成16位字符串
* @return string 生成的字符串
*/
function getRandomStr()
{
$str = "";
$str_pol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
$max = strlen($str_pol) - 1;
for ($i = 0; $i < 16; $i++) {
$str .= $str_pol[mt_rand(0, $max)];
}
return $str;
}
}
?>

@ -0,0 +1,36 @@
<?php
include_once "errorCode.php";
/**
* SHA1 class
*
* 计算公众平台的消息签名接口.
*/
class SHA1
{
/**
* 用SHA1算法生成安全签名
* @param string $token 票据
* @param string $timestamp 时间戳
* @param string $nonce 随机字符串
* @param string $encrypt 密文消息
*/
public function getSHA1($token, $timestamp, $nonce, $encrypt_msg)
{
//排序
try {
$array = array($encrypt_msg, $token, $timestamp, $nonce);
sort($array, SORT_STRING);
$str = implode($array);
return array(ErrorCode::$OK, sha1($str));
} catch (Exception $e) {
//print $e . "\n";
return array(ErrorCode::$ComputeSignatureError, null);
}
}
}
?>

@ -0,0 +1,150 @@
<?php
/**
* 对公众平台发送给公众账号的消息加解密示例代码.
*
* @copyright Copyright (c) 1998-2014 Tencent Inc.
*/
include_once "sha1.php";
include_once "xmlparse.php";
include_once "pkcs7Encoder.php";
include_once "errorCode.php";
/**
* 1.第三方回复加密消息给公众平台;
* 2.第三方收到公众平台发送的消息,验证消息的安全性,并对消息进行解密。
*/
class WXBizMsgCrypt
{
private $token;
private $encodingAesKey;
private $appId;
/**
* 构造函数
* @param $token string 公众平台上开发者设置的token
* @param $encodingAesKey string 公众平台上开发者设置的EncodingAESKey
* @param $appId string 公众平台的appId
*/
public function WXBizMsgCrypt($token, $encodingAesKey, $appId)
{
$this->token = $token;
$this->encodingAesKey = $encodingAesKey;
$this->appId = $appId;
}
/**
* 将公众平台回复用户的消息加密打包.
* <ol>
* <li>对要发送的消息进行AES-CBC加密</li>
* <li>生成安全签名</li>
* <li>将消息密文和安全签名打包成xml格式</li>
* </ol>
*
* @param $replyMsg string 公众平台待回复用户的消息xml格式的字符串
* @param $timeStamp string 时间戳可以自己生成也可以用URL参数的timestamp
* @param $nonce string 随机串可以自己生成也可以用URL参数的nonce
* @param &$encryptMsg string 加密后的可以直接回复用户的密文包括msg_signature, timestamp, nonce, encrypt的xml格式的字符串,
* 当return返回0时有效
*
* @return int 成功0失败返回对应的错误码
*/
public function encryptMsg($replyMsg, $timeStamp, $nonce, &$encryptMsg)
{
$pc = new Prpcrypt($this->encodingAesKey);
//加密
$array = $pc->encrypt($replyMsg, $this->appId);
$ret = $array[0];
if ($ret != 0) {
return $ret;
}
if ($timeStamp == null) {
$timeStamp = time();
}
$encrypt = $array[1];
//生成安全签名
$sha1 = new SHA1;
$array = $sha1->getSHA1($this->token, $timeStamp, $nonce, $encrypt);
$ret = $array[0];
if ($ret != 0) {
return $ret;
}
$signature = $array[1];
//生成发送的xml
$xmlparse = new XMLParse;
$encryptMsg = $xmlparse->generate($encrypt, $signature, $timeStamp, $nonce);
return ErrorCode::$OK;
}
/**
* 检验消息的真实性,并且获取解密后的明文.
* <ol>
* <li>利用收到的密文生成安全签名,进行签名验证</li>
* <li>若验证通过则提取xml中的加密消息</li>
* <li>对消息进行解密</li>
* </ol>
*
* @param $msgSignature string 签名串对应URL参数的msg_signature
* @param $timestamp string 时间戳 对应URL参数的timestamp
* @param $nonce string 随机串对应URL参数的nonce
* @param $postData string 密文对应POST请求的数据
* @param &$msg string 解密后的原文当return返回0时有效
*
* @return int 成功0失败返回对应的错误码
*/
public function decryptMsg($msgSignature, $timestamp = null, $nonce, $postData, &$msg)
{
if (strlen($this->encodingAesKey) != 43) {
return ErrorCode::$IllegalAesKey;
}
$pc = new Prpcrypt($this->encodingAesKey);
//提取密文
$xmlparse = new XMLParse;
$array = $xmlparse->extract($postData);
$ret = $array[0];
if ($ret != 0) {
return $ret;
}
if ($timestamp == null) {
$timestamp = time();
}
$encrypt = $array[1];
$touser_name = $array[2];
//验证安全签名
$sha1 = new SHA1;
$array = $sha1->getSHA1($this->token, $timestamp, $nonce, $encrypt);
$ret = $array[0];
if ($ret != 0) {
return $ret;
}
$signature = $array[1];
if ($signature != $msgSignature) {
return ErrorCode::$ValidateSignatureError;
}
$result = $pc->decrypt($encrypt, $this->appId);
if ($result[0] != 0) {
return $result[0];
}
$msg = $result[1];
return ErrorCode::$OK;
}
}

@ -0,0 +1,55 @@
<?php
include_once "errorCode.php";
/**
* XMLParse class
*
* 提供提取消息格式中的密文及生成回复消息格式的接口.
*/
class XMLParse
{
/**
* 提取出xml数据包中的加密消息
* @param string $xmltext 待提取的xml字符串
* @return string 提取出的加密消息字符串
*/
public function extract($xmltext)
{
libxml_disable_entity_loader(true);
try {
$xml = new DOMDocument();
$xml->loadXML($xmltext);
$array_e = $xml->getElementsByTagName('Encrypt');
$array_a = $xml->getElementsByTagName('ToUserName');
$encrypt = $array_e->item(0)->nodeValue;
$tousername = $array_a->item(0)->nodeValue;
return array(0, $encrypt, $tousername);
} catch (Exception $e) {
//print $e . "\n";
return array(ErrorCode::$ParseXmlError, null, null);
}
}
/**
* 生成xml消息
* @param string $encrypt 加密后的消息密文
* @param string $signature 安全签名
* @param string $timestamp 时间戳
* @param string $nonce 随机字符串
*/
public function generate($encrypt, $signature, $timestamp, $nonce)
{
$format = "<xml>
<Encrypt><![CDATA[%s]]></Encrypt>
<MsgSignature><![CDATA[%s]]></MsgSignature>
<TimeStamp>%s</TimeStamp>
<Nonce><![CDATA[%s]]></Nonce>
</xml>";
return sprintf($format, $encrypt, $signature, $timestamp, $nonce);
}
}
?>

@ -0,0 +1,84 @@
<?php
require_once "lib/WxPay.Api.php";
require_once "WxPay.Config.php";
require_once "WxPay.JsApiPay.php";
defined('BASEPATH') OR exit('No direct script access allowed');
/**
*
* 刷卡支付实现类
* @author widyhu
*
*/
class NativePay
{
protected $ci;
public function __construct()
{
$this->ci =& get_instance();
}
/**
*
* 生成扫描支付URL,模式一
* @param BizPayUrlInput $bizUrlInfo
*/
public function GetPrePayUrl($productId)
{
$biz = new WxPayBizPayUrl();
$biz->SetProduct_id($productId);
try{
$config = new WxPayConfig();
$values = WxpayApi::bizpayurl($config, $biz);
} catch(Exception $e) {
// Log::ERROR(json_encode($e));
}
$url = "weixin://wxpay/bizpayurl?" . $this->ToUrlParams($values);
return $url;
}
/**
*
* 参数数组转换为url参数
* @param array $urlObj
*/
private function ToUrlParams($urlObj)
{
$buff = "";
foreach ($urlObj as $k => $v)
{
$buff .= $k . "=" . $v . "&";
}
$buff = trim($buff, "&");
return $buff;
}
/**
*
* 生成直接支付url支付url有效期为2小时,模式二
* @param UnifiedOrderInput $input
*/
public function GetPayUrl($input)
{
// if($input->GetTrade_type() == "NATIVE")
// {
try{
$config = new WxPayConfig();
$result = WxPayApi::unifiedOrder($config, $input);
// log_message('error',var_export($input, 1));
// Log::ERROR(var_export($input, 1));
return $result;
} catch(Exception $e) {
log_message('error','testlog 2' . var_export($e, 1));
// Log::ERROR(var_export($e, 1));
// Log::ERROR(json_encode($e));
}
// }
// return false;
}
}

@ -0,0 +1,110 @@
<?php
require_once "lib/WxPay.Config.Interface.php";
class WxPayConfig extends WxPayConfigInterface
{
public function __construct()
{
$this->ci =& get_instance();
$this->ci->config->load('wechat', true);
$this->wx_site_config = $this->ci->config->item($GLOBALS['__WX_SITE_NAME__'], 'wechat');
}
//=======【基本信息设置】=====================================
/**
* TODO: 修改这里配置为您自己申请的商户信息
* 微信公众号信息配置
*
* APPID绑定支付的APPID必须配置开户邮件中可查看
*
* MCHID商户号必须配置开户邮件中可查看
*
*/
public function GetAppId()
{
return $this->wx_site_config['app_id'];
}
public function GetMerchantId()
{
return $this->wx_site_config['mch_id'];
}
//=======【支付相关配置:支付成功回调地址/签名方式】===================================
/**
* TODO:支付回调url
* 签名和验证签名方式, 支持md5和sha256方式
**/
public function GetNotifyUrl()
{
return $this->wx_site_config['notify_url'];
}
public function GetSignType()
{
return $this->ci->config->item('sign_type', 'wechat');
}
//=======【curl代理设置】===================================
/**
* TODO这里设置代理机器只有需要代理的时候才设置不需要代理请设置为0.0.0.0和0
* 本例程通过curl使用HTTP POST方法此处可修改代理服务器
* 默认CURL_PROXY_HOST=0.0.0.0和CURL_PROXY_PORT=0此时不开启代理如有需要才设置
* @var unknown_type
*/
public function GetProxy(&$proxyHost, &$proxyPort)
{
$proxyHost = "0.0.0.0";
$proxyPort = 0;
}
//=======【上报信息配置】===================================
/**
* TODO接口调用上报等级默认紧错误上报注意上报超时间为【1s】上报无论成败【永不抛出异常】
* 不会影响接口调用流程),开启上报之后,方便微信监控请求调用的质量,建议至少
* 开启错误上报。
* 上报等级0.关闭上报; 1.仅错误出错上报; 2.全量上报
* @var int
*/
public function GetReportLevenl()
{
return 1;
}
//=======【商户密钥信息-需要业务方继承】===================================
/*
* KEY商户支付密钥参考开户邮件设置必须配置登录商户平台自行设置, 请妥善保管, 避免密钥泄露
* 设置地址https://pay.weixin.qq.com/index.php/account/api_cert
*
* APPSECRET公众帐号secert仅JSAPI支付的时候需要配置 登录公众平台,进入开发者中心可设置), 请妥善保管, 避免密钥泄露
* 获取地址https://mp.weixin.qq.com/advanced/advanced?action=dev&t=advanced/dev&token=2005451881&lang=zh_CN
* @var string
*/
public function GetKey()
{
return $this->wx_site_config['key'];
}
public function GetAppSecret()
{
return $this->wx_site_config['app_secret'];
}
//=======【证书路径设置-需要业务方继承】=====================================
/**
* TODO设置商户证书路径
* 证书路径,注意应该填写绝对路径(仅退款、撤销订单时需要,可登录商户平台下载,
* API证书下载地址https://pay.weixin.qq.com/index.php/account/api_cert下载之前需要安装商户操作证书
* 注意:
* 1.证书文件不能放在web服务器虚拟目录应放在有访问权限控制的目录中防止被他人下载
* 2.建议将证书文件名改为复杂且不容易猜测的文件名;
* 3.商户服务器要做好病毒和木马防护工作,不被非法侵入者窃取证书文件。
* @var path
*/
public function GetSSLCertPath(&$sslCertPath, &$sslKeyPath)
{
$sslCertPath = '../cert/apiclient_cert.pem';
$sslKeyPath = '../cert/apiclient_key.pem';
}
}

@ -0,0 +1,230 @@
<?php
/**
*
* example目录下为简单的支付样例仅能用于搭建快速体验微信支付使用
* 样例的作用仅限于指导如何使用sdk在安全上面仅做了简单处理 复制使用样例代码时请慎重
* 请勿直接直接使用样例对外提供服务
*
**/
require_once "lib/WxPay.Api.php";
require_once "WxPay.Config.php";
/**
*
* JSAPI支付实现类
* 该类实现了从微信公众平台获取code、通过code获取openid和access_token、
* 生成jsapi支付js接口所需的参数、生成获取共享收货地址所需的参数
*
* 该类是微信支付提供的样例程序商户可根据自己的需求修改或者使用lib中的api自行开发
*
* @author widy
*
*/
class JsApiPay
{
/**
*
* 网页授权接口微信服务器返回的数据,返回样例如下
* {
* "access_token":"ACCESS_TOKEN",
* "expires_in":7200,
* "refresh_token":"REFRESH_TOKEN",
* "openid":"OPENID",
* "scope":"SCOPE",
* "unionid": "o6_bmasdasdsad6_2sgVt7hMZOPfL"
* }
* 其中access_token可用于获取共享收货地址
* openid是微信支付jsapi支付接口必须的参数
* @var array
*/
public $data = null;
/**
*
* 通过跳转获取用户的openid跳转流程如下
* 1、设置自己需要调回的url及其其他参数跳转到微信服务器https://open.weixin.qq.com/connect/oauth2/authorize
* 2、微信服务处理完成之后会跳转回用户redirect_uri地址此时会带上一些参数code
*
* @return 用户的openid
*/
public function GetOpenid()
{
//通过code获得openid
if (!isset($_GET['code'])){
//触发微信返回code码
$baseUrl = urlencode('http://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'].$_SERVER['QUERY_STRING']);
$url = $this->_CreateOauthUrlForCode($baseUrl);
Header("Location: $url");
exit();
} else {
//获取code码以获取openid
$code = $_GET['code'];
$openid = $this->getOpenidFromMp($code);
return $openid;
}
}
/**
*
* 获取jsapi支付的参数
* @param array $UnifiedOrderResult 统一支付接口返回的数据
* @throws WxPayException
*
* @return json数据可直接填入js函数作为参数
*/
public function GetJsApiParameters($UnifiedOrderResult)
{
if(!array_key_exists("appid", $UnifiedOrderResult)
|| !array_key_exists("prepay_id", $UnifiedOrderResult)
|| $UnifiedOrderResult['prepay_id'] == "")
{
log_message('error','参数错误:' . PHP_EOL . var_export($UnifiedOrderResult, 1));
}
$jsapi = new WxPayJsApiPay();
$jsapi->SetAppid($UnifiedOrderResult["appid"]);
$timeStamp = time();
$jsapi->SetTimeStamp("$timeStamp");
$jsapi->SetNonceStr(WxPayApi::getNonceStr());
$jsapi->SetPackage("prepay_id=" . $UnifiedOrderResult['prepay_id']);
$config = new WxPayConfig();
$jsapi->SetPaySign($jsapi->MakeSign($config));
$parameters = json_encode($jsapi->GetValues());
return $parameters;
}
/**
*
* 通过code从工作平台获取openid机器access_token
* @param string $code 微信跳转回来带上的code
*
* @return openid
*/
public function GetOpenidFromMp($code)
{
$url = $this->__CreateOauthUrlForOpenid($code);
//初始化curl
$ch = curl_init();
$curlVersion = curl_version();
$config = new WxPayConfig();
$ua = "WXPaySDK/3.0.9 (".PHP_OS.") PHP/".PHP_VERSION." CURL/".$curlVersion['version']." "
.$config->GetMerchantId();
//设置超时
curl_setopt($ch, CURLOPT_TIMEOUT, $this->curl_timeout);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, $ua);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$proxyHost = "0.0.0.0";
$proxyPort = 0;
$config->GetProxy($proxyHost, $proxyPort);
if($proxyHost != "0.0.0.0" && $proxyPort != 0){
curl_setopt($ch,CURLOPT_PROXY, $proxyHost);
curl_setopt($ch,CURLOPT_PROXYPORT, $proxyPort);
}
//运行curl结果以jason形式返回
$res = curl_exec($ch);
curl_close($ch);
//取出openid
$data = json_decode($res,true);
$this->data = $data;
$openid = $data['openid'];
return $openid;
}
/**
*
* 拼接签名字符串
* @param array $urlObj
*
* @return 返回已经拼接好的字符串
*/
private function ToUrlParams($urlObj)
{
$buff = "";
foreach ($urlObj as $k => $v)
{
if($k != "sign"){
$buff .= $k . "=" . $v . "&";
}
}
$buff = trim($buff, "&");
return $buff;
}
/**
*
* 获取地址js参数
*
* @return 获取共享收货地址js函数需要的参数json格式可以直接做参数使用
*/
public function GetEditAddressParameters()
{
$config = new WxPayConfig();
$getData = $this->data;
$data = array();
$data["appid"] = $config->GetAppId();
$data["url"] = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$time = time();
$data["timestamp"] = "$time";
$data["noncestr"] = WxPayApi::getNonceStr();
$data["accesstoken"] = $getData["access_token"];
ksort($data);
$params = $this->ToUrlParams($data);
$addrSign = sha1($params);
$afterData = array(
"addrSign" => $addrSign,
"signType" => "sha1",
"scope" => "jsapi_address",
"appId" => $config->GetAppId(),
"timeStamp" => $data["timestamp"],
"nonceStr" => $data["noncestr"]
);
$parameters = json_encode($afterData);
return $parameters;
}
/**
*
* 构造获取code的url连接
* @param string $redirectUrl 微信服务器回跳的url需要url编码
*
* @return 返回构造好的url
*/
private function _CreateOauthUrlForCode($redirectUrl)
{
$config = new WxPayConfig();
$urlObj["appid"] = $config->GetAppId();
$urlObj["redirect_uri"] = "$redirectUrl";
$urlObj["response_type"] = "code";
$urlObj["scope"] = "snsapi_base";
$urlObj["state"] = "STATE"."#wechat_redirect";
$bizString = $this->ToUrlParams($urlObj);
return "https://open.weixin.qq.com/connect/oauth2/authorize?".$bizString;
}
/**
*
* 构造获取open和access_toke的url地址
* @param string $code微信跳转带回的code
*
* @return 请求的url
*/
private function __CreateOauthUrlForOpenid($code)
{
$config = new WxPayConfig();
$urlObj["appid"] = $config->GetAppId();
$urlObj["secret"] = $config->GetAppSecret();
$urlObj["code"] = $code;
$urlObj["grant_type"] = "authorization_code";
$bizString = $this->ToUrlParams($urlObj);
return "https://api.weixin.qq.com/sns/oauth2/access_token?".$bizString;
}
}

@ -0,0 +1,166 @@
<?php
/**
*
* example目录下为简单的支付样例仅能用于搭建快速体验微信支付使用
* 样例的作用仅限于指导如何使用sdk在安全上面仅做了简单处理 复制使用样例代码时请慎重
* 请勿直接直接使用样例对外提供服务
*
**/
require_once "lib/WxPay.Api.php";
require_once "WxPay.Config.php";
/**
*
* 刷卡支付实现类
* 该类实现了一个刷卡支付的流程,流程如下:
* 1、提交刷卡支付
* 2、根据返回结果决定是否需要查询订单如果查询之后订单还未变则需要返回查询一般反复查10次
* 3、如果反复查询10订单依然不变则发起撤销订单
* 4、撤销订单需要循环撤销一直撤销成功为止注意循环次数建议10次
*
* 该类是微信支付提供的样例程序商户可根据自己的需求修改或者使用lib中的api自行开发为了防止
* 查询时hold住后台php进程商户查询和撤销逻辑可在前端调用
*
* @author widy
*
*/
class MicroPay
{
/**
*
* 提交刷卡支付,并且确认结果,接口比较慢
* @param WxPayMicroPay $microPayInput
* @throws WxpayException
* @return 返回查询接口的结果
*/
public function pay($microPayInput)
{
//①、提交被扫支付
$config = new WxPayConfig();
$result = WxPayApi::micropay($config, $microPayInput, 5);
//如果返回成功
if(!array_key_exists("return_code", $result)
|| !array_key_exists("result_code", $result))
{
echo "接口调用失败,请确认是否输入是否有误!";
throw new WxPayException("接口调用失败!");
}
//取订单号
$out_trade_no = $microPayInput->GetOut_trade_no();
//②、接口调用成功,明确返回调用失败
if($result["return_code"] == "SUCCESS" &&
$result["result_code"] == "FAIL" &&
$result["err_code"] != "USERPAYING" &&
$result["err_code"] != "SYSTEMERROR")
{
return false;
}
//③、确认支付是否成功
$queryTimes = 10;
while($queryTimes > 0)
{
$succResult = 0;
$queryResult = $this->query($out_trade_no, $succResult);
//如果需要等待1s后继续
if($succResult == 2){
sleep(2);
continue;
} else if($succResult == 1){//查询成功
return $queryResult;
} else {//订单交易失败
break;
}
}
//④、次确认失败,则撤销订单
if(!$this->cancel($out_trade_no))
{
throw new WxpayException("撤销单失败!");
}
return false;
}
/**
*
* 查询订单情况
* @param string $out_trade_no 商户订单号
* @param int $succCode 查询订单结果
* @return 0 订单不成功1表示订单成功2表示继续等待
*/
public function query($out_trade_no, &$succCode)
{
$queryOrderInput = new WxPayOrderQuery();
$queryOrderInput->SetOut_trade_no($out_trade_no);
$config = new WxPayConfig();
try{
$result = WxPayApi::orderQuery($config, $queryOrderInput);
} catch(Exception $e) {
Log::ERROR(json_encode($e));
}
if($result["return_code"] == "SUCCESS"
&& $result["result_code"] == "SUCCESS")
{
//支付成功
if($result["trade_state"] == "SUCCESS"){
$succCode = 1;
return $result;
}
//用户支付中
else if($result["trade_state"] == "USERPAYING"){
$succCode = 2;
return false;
}
}
//如果返回错误码为“此交易订单号不存在”则直接认定失败
if($result["err_code"] == "ORDERNOTEXIST")
{
$succCode = 0;
} else{
//如果是系统错误,则后续继续
$succCode = 2;
}
return false;
}
/**
*
* 撤销订单如果失败会重复调用10次
* @param string $out_trade_no
* @param 调用深度 $depth
*/
public function cancel($out_trade_no, $depth = 0)
{
try {
if($depth > 10){
return false;
}
$clostOrder = new WxPayReverse();
$clostOrder->SetOut_trade_no($out_trade_no);
$config = new WxPayConfig();
$result = WxPayApi::reverse($config, $clostOrder);
//接口调用失败
if($result["return_code"] != "SUCCESS"){
return false;
}
//如果结果为success且不需要重新调用撤销则表示撤销成功
if($result["result_code"] != "SUCCESS"
&& $result["recall"] == "N"){
return true;
} else if($result["recall"] == "Y") {
return $this->cancel($out_trade_no, ++$depth);
}
} catch(Exception $e) {
Log::ERROR(json_encode($e));
}
return false;
}
}

@ -0,0 +1,60 @@
<?php
/**
*
* example目录下为简单的支付样例仅能用于搭建快速体验微信支付使用
* 样例的作用仅限于指导如何使用sdk在安全上面仅做了简单处理 复制使用样例代码时请慎重
* 请勿直接直接使用样例对外提供服务
*
**/
require_once "../lib/WxPay.Api.php";
require_once "WxPay.Config.php";
require_once 'log.php';
//初始化日志
$logHandler= new CLogFileHandler("../logs/".date('Y-m-d').'.log');
$log = Log::Init($logHandler, 15);
if((isset($_REQUEST["bill_date"]) && !preg_match("/^[0-9-]{6,64}$/i", $_REQUEST["bill_date"], $matches))
|| (isset($_REQUEST["bill_type"]) && !preg_match("/^[A-Z]{1,64}$/i", $_REQUEST["bill_type"], $matches)))
{
header('HTTP/1.1 404 Not Found');
exit();
}
if(isset($_REQUEST["bill_date"]) && $_REQUEST["bill_date"] != ""){
$bill_date = $_REQUEST["bill_date"];
$bill_type = $_REQUEST["bill_type"];
$input = new WxPayDownloadBill();
$input->SetBill_date($bill_date);
$input->SetBill_type($bill_type);
$config = new WxPayConfig();
$file = WxPayApi::downloadBill($config, $input);
echo htmlspecialchars($file, ENT_QUOTES);
//TODO 对账单文件处理
exit(0);
}
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>微信支付样例-查退款单</title>
</head>
<body>
<form action="#" method="post">
<div style="margin-left:2%;">对账日期:</div><br/>
<input type="text" style="width:96%;height:35px;margin-left:2%;" name="bill_date" /><br /><br />
<div style="margin-left:2%;">账单类型:</div><br/>
<select style="width:96%;height:35px;margin-left:2%;" name="bill_type">
<option value ="ALL">所有订单信息</option>
<option value ="SUCCESS">成功支付的订单</option>
<option value="REFUND">退款订单</option>
<option value="REVOKED">撤销的订单</option>
</select><br /><br />
<div align="center">
<input type="submit" value="下载订单" style="width:210px; height:50px; border-radius: 15px;background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer; color:white; font-size:16px;" type="button" onclick="callpay()" />
</div>
</form>
</body>
</html>

@ -0,0 +1,77 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>微信支付样例</title>
<style type="text/css">
ul {
margin-left:10px;
margin-right:10px;
margin-top:10px;
padding: 0;
}
li {
width: 32%;
float: left;
margin: 0px;
margin-left:1%;
padding: 0px;
height: 100px;
display: inline;
line-height: 100px;
color: #fff;
font-size: x-large;
word-break:break-all;
word-wrap : break-word;
margin-bottom: 5px;
}
a {
-webkit-tap-highlight-color: rgba(0,0,0,0);
text-decoration:none;
color:#fff;
}
a:link{
-webkit-tap-highlight-color: rgba(0,0,0,0);
text-decoration:none;
color:#fff;
}
a:visited{
-webkit-tap-highlight-color: rgba(0,0,0,0);
text-decoration:none;
color:#fff;
}
a:hover{
-webkit-tap-highlight-color: rgba(0,0,0,0);
text-decoration:none;
color:#fff;
}
a:active{
-webkit-tap-highlight-color: rgba(0,0,0,0);
text-decoration:none;
color:#fff;
}
</style>
</head>
<body>
<div align="center">
<ul>
<li style="background-color:#FF7F24"><a href="/jsapi.php">JSAPI支付</a></li>
<li style="background-color:#698B22"><a href="/micropay.php">刷卡支付</a></li>
<li style="background-color:#8B6914"><a href="native.php">扫码支付</a></li>
<li style="background-color:#CDCD00"><a href="/orderquery.php">订单查询</a></li>
<li style="background-color:#CD3278"><a href="/refund.php">订单退款</a></li>
<li style="background-color:#848484"><a href="/refundquery.php">退款查询</a></li>
<li style="background-color:#8EE5EE"><a href="/download.php">下载订单</a></li>
</ul>
</div>
</body>
</html>
<!--
http://
http://
http://
http://
http://
http://
http://
-->

@ -0,0 +1,138 @@
<?php
/**
*
* example目录下为简单的支付样例仅能用于搭建快速体验微信支付使用
* 样例的作用仅限于指导如何使用sdk在安全上面仅做了简单处理 复制使用样例代码时请慎重
* 请勿直接直接使用样例对外提供服务
*
**/
require_once "../lib/WxPay.Api.php";
require_once "WxPay.JsApiPay.php";
require_once "WxPay.Config.php";
require_once 'log.php';
//初始化日志
$logHandler= new CLogFileHandler("../logs/".date('Y-m-d').'.log');
$log = Log::Init($logHandler, 15);
//打印输出数组信息
function printf_info($data)
{
foreach($data as $key=>$value){
echo "<font color='#00ff55;'>$key</font> : ".htmlspecialchars($value, ENT_QUOTES)." <br/>";
}
}
//①、获取用户openid
try{
$tools = new JsApiPay();
$openId = $tools->GetOpenid();
//②、统一下单
$input = new WxPayUnifiedOrder();
$input->SetBody("test");
$input->SetAttach("test");
$input->SetOut_trade_no("sdkphp".date("YmdHis"));
$input->SetTotal_fee("1");
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 600));
$input->SetGoods_tag("test");
$input->SetNotify_url("http://paysdk.weixin.qq.com/notify.php");
$input->SetTrade_type("JSAPI");
$input->SetOpenid($openId);
$config = new WxPayConfig();
$order = WxPayApi::unifiedOrder($config, $input);
echo '<font color="#f00"><b>统一下单支付单信息</b></font><br/>';
printf_info($order);
$jsApiParameters = $tools->GetJsApiParameters($order);
//获取共享收货地址js函数参数
$editAddress = $tools->GetEditAddressParameters();
} catch(Exception $e) {
Log::ERROR(json_encode($e));
}
//③、在支持成功回调通知中处理成功之后的事宜,见 notify.php
/**
* 注意:
* 1、当你的回调地址不可访问的时候回调通知会失败可以通过查询订单来确认支付是否成功
* 2、jsapi支付时需要填入用户openidWxPay.JsApiPay.php中有获取openid流程 (文档可以参考微信公众平台“网页授权接口”,
* 参考http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html
*/
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>微信支付样例-支付</title>
<script type="text/javascript">
//调用微信JS api 支付
function jsApiCall()
{
WeixinJSBridge.invoke(
'getBrandWCPayRequest',
<?php echo $jsApiParameters; ?>,
function(res){
WeixinJSBridge.log(res.err_msg);
alert(res.err_code+res.err_desc+res.err_msg);
}
);
}
function callpay()
{
if (typeof WeixinJSBridge == "undefined"){
if( document.addEventListener ){
document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
}else if (document.attachEvent){
document.attachEvent('WeixinJSBridgeReady', jsApiCall);
document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
}
}else{
jsApiCall();
}
}
</script>
<script type="text/javascript">
//获取共享地址
function editAddress()
{
WeixinJSBridge.invoke(
'editAddress',
<?php echo $editAddress; ?>,
function(res){
var value1 = res.proviceFirstStageName;
var value2 = res.addressCitySecondStageName;
var value3 = res.addressCountiesThirdStageName;
var value4 = res.addressDetailInfo;
var tel = res.telNumber;
alert(value1 + value2 + value3 + value4 + ":" + tel);
}
);
}
window.onload = function(){
if (typeof WeixinJSBridge == "undefined"){
if( document.addEventListener ){
document.addEventListener('WeixinJSBridgeReady', editAddress, false);
}else if (document.attachEvent){
document.attachEvent('WeixinJSBridgeReady', editAddress);
document.attachEvent('onWeixinJSBridgeReady', editAddress);
}
}else{
editAddress();
}
};
</script>
</head>
<body>
<br/>
<font color="#9ACD32"><b>该笔订单支付金额为<span style="color:#f00;font-size:50px">1分</span></b></font><br/><br/>
<div align="center">
<button style="width:210px; height:50px; border-radius: 15px;background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer; color:white; font-size:16px;" type="button" onclick="callpay()" >立即支付</button>
</div>
</body>
</html>

@ -0,0 +1,618 @@
<?php
require_once "WxPay.Exception.php";
require_once "WxPay.Config.Interface.php";
require_once "WxPay.Data.php";
/**
*
* 接口访问类包含所有微信支付API列表的封装类中方法为static方法
* 每个接口有默认超时时间除提交被扫支付为10s上报超时时间为1s外其他均为6s
* @author widyhu
*
*/
class WxPayApi
{
/**
*
* 统一下单WxPayUnifiedOrder中out_trade_no、body、total_fee、trade_type必填
* appid、mchid、spbill_create_ip、nonce_str不需要填入
* @param WxPayConfigInterface $config 配置对象
* @param WxPayUnifiedOrder $inputObj
* @param int $timeOut
* @throws WxPayException
* @return 成功时返回,其他抛异常
*/
public static function unifiedOrder($config, $inputObj, $timeOut = 6)
{
$url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
//检测必填参数
if(!$inputObj->IsOut_trade_noSet()) {
log_message('error','缺少统一支付接口必填参数out_trade_no');
}else if(!$inputObj->IsBodySet()){
log_message('error',"缺少统一支付接口必填参数body");
}else if(!$inputObj->IsTotal_feeSet()) {
log_message('error',"缺少统一支付接口必填参数total_fee");
}else if(!$inputObj->IsTrade_typeSet()) {
log_message('error',"缺少统一支付接口必填参数trade_type");
}
//关联参数
if($inputObj->GetTrade_type() == "JSAPI" && !$inputObj->IsOpenidSet()){
log_message('error',"统一支付接口中缺少必填参数openidtrade_type为JSAPI时openid为必填参数");
}
if($inputObj->GetTrade_type() == "NATIVE" && !$inputObj->IsProduct_idSet()){
log_message('error',"统一支付接口中缺少必填参数product_idtrade_type为JSAPI时product_id为必填参数");
}
//异步通知url未设置则使用配置文件中的url
if(!$inputObj->IsNotify_urlSet() && $config->GetNotifyUrl() != ""){
$inputObj->SetNotify_url($config->GetNotifyUrl());//异步通知url
}
$inputObj->SetAppid($config->GetAppId());//公众账号ID
$inputObj->SetMch_id($config->GetMerchantId());//商户号
$inputObj->SetSpbill_create_ip($_SERVER['REMOTE_ADDR']);//终端ip
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
//签名
$inputObj->SetSign($config);
$xml = $inputObj->ToXml();
$startTimeStamp = self::getMillisecond();//请求开始时间
$response = self::postXmlCurl($config, $xml, $url, false, $timeOut);
$result = WxPayResults::Init($config, $response);
self::reportCostTime($config, $url, $startTimeStamp, $result);//上报请求花费时间
return $result;
}
/**
*
* 查询订单WxPayOrderQuery中out_trade_no、transaction_id至少填一个
* appid、mchid、spbill_create_ip、nonce_str不需要填入
* @param WxPayConfigInterface $config 配置对象
* @param WxPayOrderQuery $inputObj
* @param int $timeOut
* @throws WxPayException
* @return 成功时返回,其他抛异常
*/
public static function orderQuery($config, $inputObj, $timeOut = 6)
{
$url = "https://api.mch.weixin.qq.com/pay/orderquery";
//检测必填参数
if(!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) {
log_message('error',"订单查询接口中out_trade_no、transaction_id至少填一个");
}
$inputObj->SetAppid($config->GetAppId());//公众账号ID
$inputObj->SetMch_id($config->GetMerchantId());//商户号
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
$inputObj->SetSign($config);//签名
$xml = $inputObj->ToXml();
$startTimeStamp = self::getMillisecond();//请求开始时间
$response = self::postXmlCurl($config, $xml, $url, false, $timeOut);
$result = WxPayResults::Init($config, $response);
self::reportCostTime($config, $url, $startTimeStamp, $result);//上报请求花费时间
return $result;
}
/**
*
* 关闭订单WxPayCloseOrder中out_trade_no必填
* appid、mchid、spbill_create_ip、nonce_str不需要填入
* @param WxPayConfigInterface $config 配置对象
* @param WxPayCloseOrder $inputObj
* @param int $timeOut
* @throws WxPayException
* @return 成功时返回,其他抛异常
*/
public static function closeOrder($config, $inputObj, $timeOut = 6)
{
$url = "https://api.mch.weixin.qq.com/pay/closeorder";
//检测必填参数
if(!$inputObj->IsOut_trade_noSet()) {
log_message('error',"订单查询接口中out_trade_no必填");
}
$inputObj->SetAppid($config->GetAppId());//公众账号ID
$inputObj->SetMch_id($config->GetMerchantId());//商户号
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
$inputObj->SetSign($config);//签名
$xml = $inputObj->ToXml();
$startTimeStamp = self::getMillisecond();//请求开始时间
$response = self::postXmlCurl($config, $xml, $url, false, $timeOut);
$result = WxPayResults::Init($config, $response);
self::reportCostTime($config, $url, $startTimeStamp, $result);//上报请求花费时间
return $result;
}
/**
*
* 申请退款WxPayRefund中out_trade_no、transaction_id至少填一个且
* out_refund_no、total_fee、refund_fee、op_user_id为必填参数
* appid、mchid、spbill_create_ip、nonce_str不需要填入
* @param WxPayConfigInterface $config 配置对象
* @param WxPayRefund $inputObj
* @param int $timeOut
* @throws WxPayException
* @return 成功时返回,其他抛异常
*/
public static function refund($config, $inputObj, $timeOut = 6)
{
$url = "https://api.mch.weixin.qq.com/secapi/pay/refund";
//检测必填参数
if(!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) {
log_message('error',"退款申请接口中out_trade_no、transaction_id至少填一个");
}else if(!$inputObj->IsOut_refund_noSet()){
log_message('error',"退款申请接口中缺少必填参数out_refund_no");
}else if(!$inputObj->IsTotal_feeSet()){
log_message('error',"退款申请接口中缺少必填参数total_fee");
}else if(!$inputObj->IsRefund_feeSet()){
log_message('error',"退款申请接口中缺少必填参数refund_fee");
}else if(!$inputObj->IsOp_user_idSet()){
log_message('error',"退款申请接口中缺少必填参数op_user_id");
}
$inputObj->SetAppid($config->GetAppId());//公众账号ID
$inputObj->SetMch_id($config->GetMerchantId());//商户号
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
$inputObj->SetSign($config);//签名
$xml = $inputObj->ToXml();
$startTimeStamp = self::getMillisecond();//请求开始时间
$response = self::postXmlCurl($config, $xml, $url, true, $timeOut);
$result = WxPayResults::Init($config, $response);
self::reportCostTime($config, $url, $startTimeStamp, $result);//上报请求花费时间
return $result;
}
/**
*
* 查询退款
* 提交退款申请后,通过调用该接口查询退款状态。退款有一定延时,
* 用零钱支付的退款20分钟内到账银行卡支付的退款3个工作日后重新查询退款状态。
* WxPayRefundQuery中out_refund_no、out_trade_no、transaction_id、refund_id四个参数必填一个
* appid、mchid、spbill_create_ip、nonce_str不需要填入
* @param WxPayConfigInterface $config 配置对象
* @param WxPayRefundQuery $inputObj
* @param int $timeOut
* @throws WxPayException
* @return 成功时返回,其他抛异常
*/
public static function refundQuery($config, $inputObj, $timeOut = 6)
{
$url = "https://api.mch.weixin.qq.com/pay/refundquery";
//检测必填参数
if(!$inputObj->IsOut_refund_noSet() &&
!$inputObj->IsOut_trade_noSet() &&
!$inputObj->IsTransaction_idSet() &&
!$inputObj->IsRefund_idSet()) {
log_message('error',"退款查询接口中out_refund_no、out_trade_no、transaction_id、refund_id四个参数必填一个");
}
$inputObj->SetAppid($config->GetAppId());//公众账号ID
$inputObj->SetMch_id($config->GetMerchantId());//商户号
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
$inputObj->SetSign($config);//签名
$xml = $inputObj->ToXml();
$startTimeStamp = self::getMillisecond();//请求开始时间
$response = self::postXmlCurl($config, $xml, $url, false, $timeOut);
$result = WxPayResults::Init($config, $response);
self::reportCostTime($config, $url, $startTimeStamp, $result);//上报请求花费时间
return $result;
}
/**
* 下载对账单WxPayDownloadBill中bill_date为必填参数
* appid、mchid、spbill_create_ip、nonce_str不需要填入
* @param WxPayConfigInterface $config 配置对象
* @param WxPayDownloadBill $inputObj
* @param int $timeOut
* @throws WxPayException
* @return 成功时返回,其他抛异常
*/
public static function downloadBill($config, $inputObj, $timeOut = 6)
{
$url = "https://api.mch.weixin.qq.com/pay/downloadbill";
//检测必填参数
if(!$inputObj->IsBill_dateSet()) {
log_message('error',"对账单接口中缺少必填参数bill_date");
}
$inputObj->SetAppid($config->GetAppId());//公众账号ID
$inputObj->SetMch_id($config->GetMerchantId());//商户号
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
$inputObj->SetSign($config);//签名
$xml = $inputObj->ToXml();
$response = self::postXmlCurl($config, $xml, $url, false, $timeOut);
if(substr($response, 0 , 5) == "<xml>"){
return "";
}
return $response;
}
/**
* 提交被扫支付API
* 收银员使用扫码设备读取微信用户刷卡授权码以后,二维码或条码信息传送至商户收银台,
* 由商户收银台或者商户后台调用该接口发起支付。
* WxPayWxPayMicroPay中body、out_trade_no、total_fee、auth_code参数必填
* appid、mchid、spbill_create_ip、nonce_str不需要填入
* @param WxPayConfigInterface $config 配置对象
* @param WxPayWxPayMicroPay $inputObj
* @param int $timeOut
*/
public static function micropay($config, $inputObj, $timeOut = 10)
{
$url = "https://api.mch.weixin.qq.com/pay/micropay";
//检测必填参数
if(!$inputObj->IsBodySet()) {
log_message('error',"提交被扫支付API接口中缺少必填参数body");
} else if(!$inputObj->IsOut_trade_noSet()) {
log_message('error',"提交被扫支付API接口中缺少必填参数out_trade_no");
} else if(!$inputObj->IsTotal_feeSet()) {
log_message('error',"提交被扫支付API接口中缺少必填参数total_fee");
} else if(!$inputObj->IsAuth_codeSet()) {
log_message('error',"提交被扫支付API接口中缺少必填参数auth_code");
}
$inputObj->SetSpbill_create_ip($_SERVER['REMOTE_ADDR']);//终端ip
$inputObj->SetAppid($config->GetAppId());//公众账号ID
$inputObj->SetMch_id($config->GetMerchantId());//商户号
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
$inputObj->SetSign($config);//签名
$xml = $inputObj->ToXml();
$startTimeStamp = self::getMillisecond();//请求开始时间
$response = self::postXmlCurl($config, $xml, $url, false, $timeOut);
$result = WxPayResults::Init($config, $response);
self::reportCostTime($config, $url, $startTimeStamp, $result);//上报请求花费时间
return $result;
}
/**
*
* 撤销订单API接口WxPayReverse中参数out_trade_no和transaction_id必须填写一个
* appid、mchid、spbill_create_ip、nonce_str不需要填入
* @param WxPayConfigInterface $config 配置对象
* @param WxPayReverse $inputObj
* @param int $timeOut
* @throws WxPayException
*/
public static function reverse($config, $inputObj, $timeOut = 6)
{
$url = "https://api.mch.weixin.qq.com/secapi/pay/reverse";
//检测必填参数
if(!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) {
log_message('error',"撤销订单API接口中参数out_trade_no和transaction_id必须填写一个");
}
$inputObj->SetAppid($config->GetAppId());//公众账号ID
$inputObj->SetMch_id($config->GetMerchantId());//商户号
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
$inputObj->SetSign($config);//签名
$xml = $inputObj->ToXml();
$startTimeStamp = self::getMillisecond();//请求开始时间
$response = self::postXmlCurl($config, $xml, $url, true, $timeOut);
$result = WxPayResults::Init($config, $response);
self::reportCostTime($config, $url, $startTimeStamp, $result);//上报请求花费时间
return $result;
}
/**
*
* 测速上报该方法内部封装在report中使用时请注意异常流程
* WxPayReport中interface_url、return_code、result_code、user_ip、execute_time_必填
* appid、mchid、spbill_create_ip、nonce_str不需要填入
* @param WxPayConfigInterface $config 配置对象
* @param WxPayReport $inputObj
* @param int $timeOut
* @throws WxPayException
* @return 成功时返回,其他抛异常
*/
public static function report($config, $inputObj, $timeOut = 1)
{
$url = "https://api.mch.weixin.qq.com/payitil/report";
//检测必填参数
if(!$inputObj->IsInterface_urlSet()) {
log_message('error',"接口URL缺少必填参数interface_url");
} if(!$inputObj->IsReturn_codeSet()) {
log_message('error',"返回状态码缺少必填参数return_code");
} if(!$inputObj->IsResult_codeSet()) {
log_message('error',"业务结果缺少必填参数result_code");
} if(!$inputObj->IsUser_ipSet()) {
log_message('error',"访问接口IP缺少必填参数user_ip");
} if(!$inputObj->IsExecute_time_Set()) {
log_message('error',"接口耗时缺少必填参数execute_time_");
}
$inputObj->SetAppid($config->GetAppId());//公众账号ID
$inputObj->SetMch_id($config->GetMerchantId());//商户号
$inputObj->SetUser_ip($_SERVER['REMOTE_ADDR']);//终端ip
$inputObj->SetTime(date("YmdHis"));//商户上报时间
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
$inputObj->SetSign($config);//签名
$xml = $inputObj->ToXml();
$startTimeStamp = self::getMillisecond();//请求开始时间
$response = self::postXmlCurl($config, $xml, $url, false, $timeOut);
return $response;
}
/**
*
* 生成二维码规则,模式一生成支付二维码
* appid、mchid、spbill_create_ip、nonce_str不需要填入
* @param WxPayConfigInterface $config 配置对象
* @param WxPayBizPayUrl $inputObj
* @param int $timeOut
* @throws WxPayException
* @return 成功时返回,其他抛异常
*/
public static function bizpayurl($config, $inputObj, $timeOut = 6)
{
if(!$inputObj->IsProduct_idSet()){
log_message('error',"生成二维码缺少必填参数product_id");
}
$inputObj->SetAppid($config->GetAppId());//公众账号ID
$inputObj->SetMch_id($config->GetMerchantId());//商户号
$inputObj->SetTime_stamp(time());//时间戳
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
$inputObj->SetSign($config);//签名
return $inputObj->GetValues();
}
/**
*
* 转换短链接
* 该接口主要用于扫码原生支付模式一中的二维码链接转成短链接(weixin://wxpay/s/XXXXXX)
* 减小二维码数据量,提升扫描速度和精确度。
* appid、mchid、spbill_create_ip、nonce_str不需要填入
* @param WxPayConfigInterface $config 配置对象
* @param WxPayShortUrl $inputObj
* @param int $timeOut
* @throws WxPayException
* @return 成功时返回,其他抛异常
*/
public static function shorturl($config, $inputObj, $timeOut = 6)
{
$url = "https://api.mch.weixin.qq.com/tools/shorturl";
//检测必填参数
if(!$inputObj->IsLong_urlSet()) {
log_message('error',"需要转换的URL签名用原串传输需URL encode");
}
$inputObj->SetAppid($config->GetAppId());//公众账号ID
$inputObj->SetMch_id($config->GetMerchantId());//商户号
$inputObj->SetNonce_str(self::getNonceStr());//随机字符串
$inputObj->SetSign($config);//签名
$xml = $inputObj->ToXml();
$startTimeStamp = self::getMillisecond();//请求开始时间
$response = self::postXmlCurl($config, $xml, $url, false, $timeOut);
$result = WxPayResults::Init($config, $response);
self::reportCostTime($config, $url, $startTimeStamp, $result);//上报请求花费时间
return $result;
}
/**
*
* 支付结果通用通知
* @param function $callback
* 直接回调函数使用方法: notify(you_function);
* 回调类成员函数方法:notify(array($this, you_function));
* $callback 原型为function function_name($data){}
*/
public static function notify($config, $callback, &$msg)
{
if (!isset($GLOBALS['HTTP_RAW_POST_DATA'])) {
# 如果没有数据,直接返回失败
return false;
}
//如果返回成功则验证签名
try {
//获取通知的数据
$xml = $GLOBALS['HTTP_RAW_POST_DATA'];
$result = WxPayNotifyResults::Init($config, $xml);
} catch (WxPayException $e){
$msg = $e->errorMessage();
return false;
}
return call_user_func($callback, $result);
}
/**
*
* 产生随机字符串不长于32位
* @param int $length
* @return 产生的随机字符串
*/
public static function getNonceStr($length = 32)
{
$chars = "abcdefghijklmnopqrstuvwxyz0123456789";
$str ="";
for ( $i = 0; $i < $length; $i++ ) {
$str .= substr($chars, mt_rand(0, strlen($chars)-1), 1);
}
return $str;
}
/**
* 直接输出xml
* @param string $xml
*/
public static function replyNotify($xml)
{
echo $xml;
}
/**
*
* 上报数据, 上报的时候将屏蔽所有异常流程
* @param WxPayConfigInterface $config 配置对象
* @param string $usrl
* @param int $startTimeStamp
* @param array $data
*/
private static function reportCostTime($config, $url, $startTimeStamp, $data)
{
//如果不需要上报数据
$reportLevenl = $config->GetReportLevenl();
if($reportLevenl == 0){
return;
}
//如果仅失败上报
if($reportLevenl == 1 &&
array_key_exists("return_code", $data) &&
$data["return_code"] == "SUCCESS" &&
array_key_exists("result_code", $data) &&
$data["result_code"] == "SUCCESS")
{
return;
}
//上报逻辑
$endTimeStamp = self::getMillisecond();
$objInput = new WxPayReport();
$objInput->SetInterface_url($url);
$objInput->SetExecute_time_($endTimeStamp - $startTimeStamp);
//返回状态码
if(array_key_exists("return_code", $data)){
$objInput->SetReturn_code($data["return_code"]);
}
//返回信息
if(array_key_exists("return_msg", $data)){
$objInput->SetReturn_msg($data["return_msg"]);
}
//业务结果
if(array_key_exists("result_code", $data)){
$objInput->SetResult_code($data["result_code"]);
}
//错误代码
if(array_key_exists("err_code", $data)){
$objInput->SetErr_code($data["err_code"]);
}
//错误代码描述
if(array_key_exists("err_code_des", $data)){
$objInput->SetErr_code_des($data["err_code_des"]);
}
//商户订单号
if(array_key_exists("out_trade_no", $data)){
$objInput->SetOut_trade_no($data["out_trade_no"]);
}
//设备号
if(array_key_exists("device_info", $data)){
$objInput->SetDevice_info($data["device_info"]);
}
try{
self::report($config, $objInput);
} catch (WxPayException $e){
//不做任何处理
}
}
/**
* 以post方式提交xml到对应的接口url
*
* @param WxPayConfigInterface $config 配置对象
* @param string $xml 需要post的xml数据
* @param string $url url
* @param bool $useCert 是否需要证书,默认不需要
* @param int $second url执行超时时间默认30s
* @throws WxPayException
*/
private static function postXmlCurl($config, $xml, $url, $useCert = false, $second = 30)
{
$ch = curl_init();
$curlVersion = curl_version();
$ua = "WXPaySDK/3.0.9 (".PHP_OS.") PHP/".PHP_VERSION." CURL/".$curlVersion['version']." "
.$config->GetMerchantId();
//设置超时
curl_setopt($ch, CURLOPT_TIMEOUT, $second);
$proxyHost = "0.0.0.0";
$proxyPort = 0;
$config->GetProxy($proxyHost, $proxyPort);
//如果有配置代理这里就设置代理
if($proxyHost != "0.0.0.0" && $proxyPort != 0){
curl_setopt($ch,CURLOPT_PROXY, $proxyHost);
curl_setopt($ch,CURLOPT_PROXYPORT, $proxyPort);
}
curl_setopt($ch,CURLOPT_URL, $url);
// curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,TRUE);
// curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,2);//严格校验
if(stripos($url,"https://")!==FALSE){
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
} else {
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,TRUE);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,2);//严格校验
}
curl_setopt($ch,CURLOPT_USERAGENT, $ua);
//设置header
curl_setopt($ch, CURLOPT_HEADER, FALSE);
//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
if($useCert == true){
//设置证书
//使用证书cert 与 key 分别属于两个.pem文件
//证书文件请放入服务器的非web目录下
$sslCertPath = "";
$sslKeyPath = "";
$config->GetSSLCertPath($sslCertPath, $sslKeyPath);
curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
curl_setopt($ch,CURLOPT_SSLCERT, $sslCertPath);
curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
curl_setopt($ch,CURLOPT_SSLKEY, $sslKeyPath);
}
//post提交方式
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
//运行curl
$data = curl_exec($ch);
//返回结果
if($data){
curl_close($ch);
return $data;
} else {
$error = curl_errno($ch);
curl_close($ch);
log_message('error',"curl出错错误码:$error " . curl_error($ch));
}
}
/**
* 获取毫秒级别的时间戳
*/
private static function getMillisecond()
{
//获取毫秒的时间戳
$time = explode ( " ", microtime () );
$time = $time[1] . ($time[0] * 1000);
$time2 = explode( ".", $time );
$time = $time2[0];
return $time;
}
}

@ -0,0 +1,76 @@
<?php
/**
* 配置账号信息
*/
abstract class WxPayConfigInterface
{
//=======【基本信息设置】=====================================
/**
* TODO: 修改这里配置为您自己申请的商户信息
* 微信公众号信息配置
*
* APPID绑定支付的APPID必须配置开户邮件中可查看
*
* MCHID商户号必须配置开户邮件中可查看
*
*/
public abstract function GetAppId();
public abstract function GetMerchantId();
//=======【支付相关配置:支付成功回调地址/签名方式】===================================
/**
* TODO:支付回调url
* 签名和验证签名方式, 支持md5和sha256方式
**/
public abstract function GetNotifyUrl();
public abstract function GetSignType();
//=======【curl代理设置】===================================
/**
* TODO这里设置代理机器只有需要代理的时候才设置不需要代理请设置为0.0.0.0和0
* 本例程通过curl使用HTTP POST方法此处可修改代理服务器
* 默认CURL_PROXY_HOST=0.0.0.0和CURL_PROXY_PORT=0此时不开启代理如有需要才设置
* @var unknown_type
*/
public abstract function GetProxy(&$proxyHost, &$proxyPort);
//=======【上报信息配置】===================================
/**
* TODO接口调用上报等级默认紧错误上报注意上报超时间为【1s】上报无论成败【永不抛出异常】
* 不会影响接口调用流程),开启上报之后,方便微信监控请求调用的质量,建议至少
* 开启错误上报。
* 上报等级0.关闭上报; 1.仅错误出错上报; 2.全量上报
* @var int
*/
public abstract function GetReportLevenl();
//=======【商户密钥信息-需要业务方继承】===================================
/*
* KEY商户支付密钥参考开户邮件设置必须配置登录商户平台自行设置, 请妥善保管, 避免密钥泄露
* 设置地址https://pay.weixin.qq.com/index.php/account/api_cert
*
* APPSECRET公众帐号secert仅JSAPI支付的时候需要配置 登录公众平台,进入开发者中心可设置), 请妥善保管, 避免密钥泄露
* 获取地址https://mp.weixin.qq.com/advanced/advanced?action=dev&t=advanced/dev&token=2005451881&lang=zh_CN
* @var string
*/
public abstract function GetKey();
public abstract function GetAppSecret();
//=======【证书路径设置-需要业务方继承】=====================================
/**
* TODO设置商户证书路径
* 证书路径,注意应该填写绝对路径(仅退款、撤销订单时需要,可登录商户平台下载,
* API证书下载地址https://pay.weixin.qq.com/index.php/account/api_cert下载之前需要安装商户操作证书
* 注意:
* 1.证书文件不能放在web服务器虚拟目录应放在有访问权限控制的目录中防止被他人下载
* 2.建议将证书文件名改为复杂且不容易猜测的文件名;
* 3.商户服务器要做好病毒和木马防护工作,不被非法侵入者窃取证书文件。
* @var path
*/
public abstract function GetSSLCertPath(&$sslCertPath, &$sslKeyPath);
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,13 @@
<?php
/**
*
* 微信支付API异常类
* @author widyhu
*
*/
class WxPayException extends Exception {
public function errorMessage()
{
return $this->getMessage();
}
}

@ -0,0 +1,105 @@
<?php
/**
*
* 回调基础类
* @author widyhu
*
*/
class WxPayNotify extends WxPayNotifyReply
{
private $config = null;
/**
*
* 回调入口
* @param bool $needSign 是否需要签名返回
*/
final public function Handle($config, $needSign = true)
{
$this->config = $config;
$msg = "OK";
//当返回false的时候表示notify中调用NotifyCallBack回调失败获取签名校验失败此时直接回复失败
$result = WxpayApi::notify($config, array($this, 'NotifyCallBack'), $msg);
if($result == false){
$this->SetReturn_code("FAIL");
$this->SetReturn_msg($msg);
$this->ReplyNotify(false);
return;
} else {
//该分支在成功回调到NotifyCallBack方法处理完成之后流程
$this->SetReturn_code("SUCCESS");
$this->SetReturn_msg("OK");
}
$this->ReplyNotify($needSign);
}
/**
*
* 回调方法入口,子类可重写该方法
//TODO 1、进行参数校验
//TODO 2、进行签名验证
//TODO 3、处理业务逻辑
* 注意:
* 1、微信回调超时时间为2s建议用户使用异步处理流程确认成功之后立刻回复微信服务器
* 2、微信服务器在调用失败或者接到回包为非确认包的时候会发起重试需确保你的回调是可以重入
* @param WxPayNotifyResults $objData 回调解释出的参数
* @param WxPayConfigInterface $config
* @param string $msg 如果回调处理失败,可以将错误信息输出到该方法
* @return true回调出来完成不需要继续回调false回调处理未完成需要继续回调
*/
public function NotifyProcess($objData, $config, &$msg)
{
//TODO 用户基础该类之后需要重写该方法成功的时候返回true失败返回false
return false;
}
/**
*
* 业务可以继承该方法打印XML方便定位.
* @param string $xmlData 返回的xml参数
*
**/
public function LogAfterProcess($xmlData)
{
return;
}
/**
*
* notify回调方法该方法中需要赋值需要输出的参数,不可重写
* @param array $data
* @return true回调出来完成不需要继续回调false回调处理未完成需要继续回调
*/
final public function NotifyCallBack($data)
{
$msg = "OK";
$result = $this->NotifyProcess($data, $this->config, $msg);
if($result == true){
$this->SetReturn_code("SUCCESS");
$this->SetReturn_msg("OK");
} else {
$this->SetReturn_code("FAIL");
$this->SetReturn_msg($msg);
}
return $result;
}
/**
*
* 回复通知
* @param bool $needSign 是否需要签名输出
*/
final private function ReplyNotify($needSign = true)
{
//如果需要签名
if($needSign == true &&
$this->GetReturn_code() == "SUCCESS")
{
$this->SetSign($this->config);
}
$xml = $this->ToXml();
$this->LogAfterProcess($xml);
WxpayApi::replyNotify($xml);
}
}

@ -0,0 +1,125 @@
<?php
//以下为日志
interface ILogHandler
{
public function write($msg);
}
class CLogFileHandler implements ILogHandler
{
private $handle = null;
public function __construct($file = '')
{
$this->handle = fopen($file,'a');
}
public function write($msg)
{
fwrite($this->handle, $msg, 4096);
}
public function __destruct()
{
fclose($this->handle);
}
}
class Log
{
private $handler = null;
private $level = 15;
private static $instance = null;
private function __construct(){}
private function __clone(){}
public static function Init($handler = null,$level = 15)
{
if(!self::$instance instanceof self)
{
self::$instance = new self();
self::$instance->__setHandle($handler);
self::$instance->__setLevel($level);
}
return self::$instance;
}
private function __setHandle($handler){
$this->handler = $handler;
}
private function __setLevel($level)
{
$this->level = $level;
}
public static function DEBUG($msg)
{
self::$instance->write(1, $msg);
}
public static function WARN($msg)
{
self::$instance->write(4, $msg);
}
public static function ERROR($msg)
{
$debugInfo = debug_backtrace();
$stack = "[";
foreach($debugInfo as $key => $val){
if(array_key_exists("file", $val)){
$stack .= ",file:" . $val["file"];
}
if(array_key_exists("line", $val)){
$stack .= ",line:" . $val["line"];
}
if(array_key_exists("function", $val)){
$stack .= ",function:" . $val["function"];
}
}
$stack .= "]";
self::$instance->write(8, $stack . $msg);
}
public static function INFO($msg)
{
self::$instance->write(2, $msg);
}
private function getLevelStr($level)
{
switch ($level)
{
case 1:
return 'debug';
break;
case 2:
return 'info';
break;
case 4:
return 'warn';
break;
case 8:
return 'error';
break;
default:
}
}
protected function write($level,$msg)
{
if(($level & $this->level) == $level )
{
$msg = '['.date('Y-m-d H:i:s').']['.$this->getLevelStr($level).'] '.$msg."\n";
$this->handler->write($msg);
}
}
}

@ -0,0 +1,73 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>微信支付样例-查退款单</title>
</head>
<?php
/**
*
* example目录下为简单的支付样例仅能用于搭建快速体验微信支付使用
* 样例的作用仅限于指导如何使用sdk在安全上面仅做了简单处理 复制使用样例代码时请慎重
* 请勿直接直接使用样例对外提供服务
*
**/
require_once "../lib/WxPay.Api.php";
require_once "WxPay.MicroPay.php";
require_once 'log.php';
if((isset($_REQUEST["auth_code"]) && !preg_match("/^[0-9]{6,64}$/i", $_REQUEST["auth_code"], $matches)))
{
header('HTTP/1.1 404 Not Found');
exit();
}
//初始化日志
$logHandler= new CLogFileHandler("../logs/".date('Y-m-d').'.log');
$log = Log::Init($logHandler, 15);
//打印输出数组信息
function printf_info($data)
{
foreach($data as $key=>$value){
echo "<font color='#00ff55;'>$key</font> : ".htmlspecialchars($value, ENT_QUOTES)." <br/>";
}
}
if(isset($_REQUEST["auth_code"]) && $_REQUEST["auth_code"] != ""){
try {
$auth_code = $_REQUEST["auth_code"];
$input = new WxPayMicroPay();
$input->SetAuth_code($auth_code);
$input->SetBody("刷卡测试样例-支付");
$input->SetTotal_fee("1");
$input->SetOut_trade_no("sdkphp".date("YmdHis"));
$microPay = new MicroPay();
printf_info($microPay->pay($input));
} catch(Exception $e) {
Log::ERROR(json_encode($e));
}
}
/**
* 注意:
* 1、提交被扫之后返回系统繁忙、用户输入密码等错误信息时需要循环查单以确定是否支付成功
* 2、多次一半10次确认都未明确成功时需要调用撤单接口撤单防止用户重复支付
*/
?>
<body>
<form action="#" method="post">
<div style="margin-left:2%;">商品描述:</div><br/>
<input type="text" style="width:96%;height:35px;margin-left:2%;" readonly value="刷卡测试样例-支付" name="auth_code" /><br /><br />
<div style="margin-left:2%;">支付金额:</div><br/>
<input type="text" style="width:96%;height:35px;margin-left:2%;" readonly value="1分" name="auth_code" /><br /><br />
<div style="margin-left:2%;">授权码:</div><br/>
<input type="text" style="width:96%;height:35px;margin-left:2%;" name="auth_code" /><br /><br />
<div align="center">
<input type="submit" value="提交刷卡" style="width:210px; height:50px; border-radius: 15px;background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer; color:white; font-size:16px;" type="button" onclick="callpay()" />
</div>
</form>
</body>
</html>

@ -0,0 +1,124 @@
<?php
/**
*
* example目录下为简单的支付样例仅能用于搭建快速体验微信支付使用
* 样例的作用仅限于指导如何使用sdk在安全上面仅做了简单处理 复制使用样例代码时请慎重
* 请勿直接直接使用样例对外提供服务
*
**/
require_once "../lib/WxPay.Api.php";
require_once '../lib/WxPay.Notify.php';
require_once "WxPay.Config.php";
require_once 'log.php';
//初始化日志
$logHandler= new CLogFileHandler("../logs/".date('Y-m-d').'.log');
$log = Log::Init($logHandler, 15);
class NativeNotifyCallBack extends WxPayNotify
{
public function unifiedorder($openId, $product_id)
{
//统一下单
$config = new WxPayConfig();
$input = new WxPayUnifiedOrder();
$input->SetBody("test");
$input->SetAttach("test");
$input->SetOut_trade_no($config->GetMerchantId().date("YmdHis"));
$input->SetTotal_fee("1");
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 600));
$input->SetGoods_tag("test");
$input->SetNotify_url("http://paysdk.weixin.qq.com/notify.php");
$input->SetTrade_type("NATIVE");
$input->SetOpenid($openId);
$input->SetProduct_id($product_id);
try {
$result = WxPayApi::unifiedOrder($config, $input);
Log::DEBUG("unifiedorder:" . json_encode($result));
} catch(Exception $e) {
Log::ERROR(json_encode($e));
}
return $result;
}
/**
*
* 回包前的回调方法
* 业务可以继承该方法,打印日志方便定位
* @param string $xmlData 返回的xml参数
*
**/
public function LogAfterProcess($xmlData)
{
Log::DEBUG("call back return xml:" . $xmlData);
return;
}
/**
* @param WxPayNotifyResults $objData 回调解释出的参数
* @param WxPayConfigInterface $config
* @param string $msg 如果回调处理失败,可以将错误信息输出到该方法
* @return true回调出来完成不需要继续回调false回调处理未完成需要继续回调
*/
public function NotifyProcess($objData, $config, &$msg)
{
$data = $objData->GetValues();
//echo "处理回调";
Log::DEBUG("call back:" . json_encode($data));
//TODO 1、进行参数校验
if(!array_key_exists("openid", $data) ||
!array_key_exists("product_id", $data))
{
$msg = "回调数据异常";
Log::DEBUG($msg . json_encode($data));
return false;
}
//TODO 2、进行签名验证
try {
$checkResult = $objData->CheckSign($config);
if($checkResult == false){
//签名错误
Log::ERROR("签名错误...");
return false;
}
} catch(Exception $e) {
Log::ERROR(json_encode($e));
}
$openid = $data["openid"];
$product_id = $data["product_id"];
//TODO 3、处理业务逻辑
//统一下单
$result = $this->unifiedorder($openid, $product_id);
if(!array_key_exists("appid", $result) ||
!array_key_exists("mch_id", $result) ||
!array_key_exists("prepay_id", $result))
{
$msg = "统一下单失败";
Log::DEBUG($msg . json_encode($data));
return false;
}
$this->SetData("appid", $result["appid"]);
$this->SetData("mch_id", $result["mch_id"]);
$this->SetData("nonce_str", WxPayApi::getNonceStr());
$this->SetData("prepay_id", $result["prepay_id"]);
$this->SetData("result_code", "SUCCESS");
$this->SetData("err_code_des", "OK");
return true;
}
}
$config = new WxPayConfig();
Log::DEBUG("begin notify!");
$notify = new NativeNotifyCallBack();
$notify->Handle($config, true);

@ -0,0 +1,105 @@
<?php
/**
*
* example目录下为简单的支付样例仅能用于搭建快速体验微信支付使用
* 样例的作用仅限于指导如何使用sdk在安全上面仅做了简单处理 复制使用样例代码时请慎重
* 请勿直接直接使用样例对外提供服务
*
**/
require_once "../lib/WxPay.Api.php";
require_once '../lib/WxPay.Notify.php';
require_once "WxPay.Config.php";
require_once 'log.php';
//初始化日志
$logHandler= new CLogFileHandler("../logs/".date('Y-m-d').'.log');
$log = Log::Init($logHandler, 15);
class PayNotifyCallBack extends WxPayNotify
{
//查询订单
public function Queryorder($transaction_id)
{
$input = new WxPayOrderQuery();
$input->SetTransaction_id($transaction_id);
$config = new WxPayConfig();
$result = WxPayApi::orderQuery($config, $input);
Log::DEBUG("query:" . json_encode($result));
if(array_key_exists("return_code", $result)
&& array_key_exists("result_code", $result)
&& $result["return_code"] == "SUCCESS"
&& $result["result_code"] == "SUCCESS")
{
return true;
}
return false;
}
/**
*
* 回包前的回调方法
* 业务可以继承该方法,打印日志方便定位
* @param string $xmlData 返回的xml参数
*
**/
public function LogAfterProcess($xmlData)
{
Log::DEBUG("call back return xml:" . $xmlData);
return;
}
//重写回调处理函数
/**
* @param WxPayNotifyResults $data 回调解释出的参数
* @param WxPayConfigInterface $config
* @param string $msg 如果回调处理失败,可以将错误信息输出到该方法
* @return true回调出来完成不需要继续回调false回调处理未完成需要继续回调
*/
public function NotifyProcess($objData, $config, &$msg)
{
$data = $objData->GetValues();
//TODO 1、进行参数校验
if(!array_key_exists("return_code", $data)
||(array_key_exists("return_code", $data) && $data['return_code'] != "SUCCESS")) {
//TODO失败,不是支付成功的通知
//如果有需要可以做失败时候的一些清理处理,并且做一些监控
$msg = "异常异常";
return false;
}
if(!array_key_exists("transaction_id", $data)){
$msg = "输入参数不正确";
return false;
}
//TODO 2、进行签名验证
try {
$checkResult = $objData->CheckSign($config);
if($checkResult == false){
//签名错误
Log::ERROR("签名错误...");
return false;
}
} catch(Exception $e) {
Log::ERROR(json_encode($e));
}
//TODO 3、处理业务逻辑
Log::DEBUG("call back:" . json_encode($data));
$notfiyOutput = array();
//查询订单,判断订单真实性
if(!$this->Queryorder($data["transaction_id"])){
$msg = "订单查询失败";
return false;
}
return true;
}
}
$config = new WxPayConfig();
Log::DEBUG("begin notify");
$notify = new PayNotifyCallBack();
$notify->Handle($config, false);

@ -0,0 +1,77 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>微信支付样例-订单查询</title>
</head>
<?php
/**
*
* example目录下为简单的支付样例仅能用于搭建快速体验微信支付使用
* 样例的作用仅限于指导如何使用sdk在安全上面仅做了简单处理 复制使用样例代码时请慎重
* 请勿直接直接使用样例对外提供服务
*
**/
require_once "../lib/WxPay.Api.php";
require_once 'log.php';
require_once "WxPay.Config.php";
if((isset($_REQUEST["transaction_id"]) && $_REQUEST["transaction_id"] != ""
&& !preg_match("/^[0-9a-zA-Z]{10,64}$/i", $_REQUEST["transaction_id"], $matches))
|| (isset($_REQUEST["out_trade_no"]) && $_REQUEST["out_trade_no"] != ""
&& !preg_match("/^[0-9a-zA-Z]{10,64}$/i", $_REQUEST["out_trade_no"], $matches))){
header('HTTP/1.1 404 Not Found');
exit();
}
//初始化日志
$logHandler= new CLogFileHandler("../logs/".date('Y-m-d').'.log');
$log = Log::Init($logHandler, 15);
function printf_info($data)
{
foreach($data as $key=>$value){
echo "<font color='#f00;'>$key</font> : ".htmlspecialchars($value, ENT_QUOTES)." <br/>";
}
}
if(isset($_REQUEST["transaction_id"]) && $_REQUEST["transaction_id"] != ""){
try {
$transaction_id = $_REQUEST["transaction_id"];
$input = new WxPayOrderQuery();
$input->SetTransaction_id($transaction_id);
$config = new WxPayConfig();
printf_info(WxPayApi::orderQuery($config, $input));
} catch(Exception $e) {
Log::ERROR(json_encode($e));
}
exit();
}
if(isset($_REQUEST["out_trade_no"]) && $_REQUEST["out_trade_no"] != ""){
try{
$out_trade_no = $_REQUEST["out_trade_no"];
$input = new WxPayOrderQuery();
$input->SetOut_trade_no($out_trade_no);
$config = new WxPayConfig();
printf_info(WxPayApi::orderQuery($config, $input));
} catch(Exception $e) {
Log::ERROR(json_encode($e));
}
exit();
}
?>
<body>
<form action="#" method="post">
<div style="margin-left:2%;color:#f00">微信订单号和商户订单号选少填一个,微信订单号优先:</div><br/>
<div style="margin-left:2%;">微信订单号:</div><br/>
<input type="text" style="width:96%;height:35px;margin-left:2%;" name="transaction_id" /><br /><br />
<div style="margin-left:2%;">商户订单号:</div><br/>
<input type="text" style="width:96%;height:35px;margin-left:2%;" name="out_trade_no" /><br /><br />
<div align="center">
<input type="submit" value="查询" style="width:210px; height:50px; border-radius: 15px;background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer; color:white; font-size:16px;" type="button" onclick="callpay()" />
</div>
</form>
</body>
</html>

File diff suppressed because it is too large Load Diff

@ -0,0 +1,167 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class QRbitstream {
protected $ci;
public function __construct()
{
$this->ci =& get_instance();
}
public $data = array();
//----------------------------------------------------------------------
public function size()
{
return count($this->data);
}
//----------------------------------------------------------------------
public function allocate($setLength)
{
$this->data = array_fill(0, $setLength, 0);
return 0;
}
//----------------------------------------------------------------------
public static function newFromNum($bits, $num)
{
$bstream = new QRbitstream();
$bstream->allocate($bits);
$mask = 1 << ($bits - 1);
for($i=0; $i<$bits; $i++) {
if($num & $mask) {
$bstream->data[$i] = 1;
} else {
$bstream->data[$i] = 0;
}
$mask = $mask >> 1;
}
return $bstream;
}
//----------------------------------------------------------------------
public static function newFromBytes($size, $data)
{
$bstream = new QRbitstream();
$bstream->allocate($size * 8);
$p=0;
for($i=0; $i<$size; $i++) {
$mask = 0x80;
for($j=0; $j<8; $j++) {
if($data[$i] & $mask) {
$bstream->data[$p] = 1;
} else {
$bstream->data[$p] = 0;
}
$p++;
$mask = $mask >> 1;
}
}
return $bstream;
}
//----------------------------------------------------------------------
public function append(QRbitstream $arg)
{
if (is_null($arg)) {
return -1;
}
if($arg->size() == 0) {
return 0;
}
if($this->size() == 0) {
$this->data = $arg->data;
return 0;
}
$this->data = array_values(array_merge($this->data, $arg->data));
return 0;
}
//----------------------------------------------------------------------
public function appendNum($bits, $num)
{
if ($bits == 0)
return 0;
$b = QRbitstream::newFromNum($bits, $num);
if(is_null($b))
return -1;
$ret = $this->append($b);
unset($b);
return $ret;
}
//----------------------------------------------------------------------
public function appendBytes($size, $data)
{
if ($size == 0)
return 0;
$b = QRbitstream::newFromBytes($size, $data);
if(is_null($b))
return -1;
$ret = $this->append($b);
unset($b);
return $ret;
}
//----------------------------------------------------------------------
public function toByte()
{
$size = $this->size();
if($size == 0) {
return array();
}
$data = array_fill(0, (int)(($size + 7) / 8), 0);
$bytes = (int)($size / 8);
$p = 0;
for($i=0; $i<$bytes; $i++) {
$v = 0;
for($j=0; $j<8; $j++) {
$v = $v << 1;
$v |= $this->data[$p];
$p++;
}
$data[$i] = $v;
}
if($size & 7) {
$v = 0;
for($j=0; $j<($size & 7); $j++) {
$v = $v << 1;
$v |= $this->data[$p];
$p++;
}
$data[$bytes] = $v;
}
return $data;
}
}
/* End of file */
/* Location: ./application/libraries/ */

@ -0,0 +1,159 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Qrcode
{
protected $ci;
public function __construct()
{
$this->ci =& get_instance();
}
public $version;
public $width;
public $data;
//----------------------------------------------------------------------
public function encodeMask(QRinput $input, $mask)
{
if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) {
throw new Exception('wrong version');
}
if($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) {
throw new Exception('wrong level');
}
$raw = new QRrawcode($input);
QRtools::markTime('after_raw');
$version = $raw->version;
$width = QRspec::getWidth($version);
$frame = QRspec::newFrame($version);
$filler = new FrameFiller($width, $frame);
if(is_null($filler)) {
return NULL;
}
// inteleaved data and ecc codes
for($i=0; $i<$raw->dataLength + $raw->eccLength; $i++) {
$code = $raw->getCode();
$bit = 0x80;
for($j=0; $j<8; $j++) {
$addr = $filler->next();
$filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0));
$bit = $bit >> 1;
}
}
QRtools::markTime('after_filler');
unset($raw);
// remainder bits
$j = QRspec::getRemainder($version);
for($i=0; $i<$j; $i++) {
$addr = $filler->next();
$filler->setFrameAt($addr, 0x02);
}
$frame = $filler->frame;
unset($filler);
// masking
$maskObj = new QRmask();
if($mask < 0) {
if (QR_FIND_BEST_MASK) {
$masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel());
} else {
$masked = $maskObj->makeMask($width, $frame, (intval(QR_DEFAULT_MASK) % 8), $input->getErrorCorrectionLevel());
}
} else {
$masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel());
}
if($masked == NULL) {
return NULL;
}
QRtools::markTime('after_mask');
$this->version = $version;
$this->width = $width;
$this->data = $masked;
return $this;
}
//----------------------------------------------------------------------
public function encodeInput(QRinput $input)
{
return $this->encodeMask($input, -1);
}
//----------------------------------------------------------------------
public function encodeString8bit($string, $version, $level)
{
if(string == NULL) {
throw new Exception('empty string!');
return NULL;
}
$input = new QRinput($version, $level);
if($input == NULL) return NULL;
$ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string));
if($ret < 0) {
unset($input);
return NULL;
}
return $this->encodeInput($input);
}
//----------------------------------------------------------------------
public function encodeString($string, $version, $level, $hint, $casesensitive)
{
if($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) {
throw new Exception('bad hint');
return NULL;
}
$input = new QRinput($version, $level);
if($input == NULL) return NULL;
$ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive);
if($ret < 0) {
return NULL;
}
return $this->encodeInput($input);
}
//----------------------------------------------------------------------
public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false)
{
$enc = QRencode::factory($level, $size, $margin);
return $enc->encodePNG($text, $outfile, $saveandprint=false);
}
//----------------------------------------------------------------------
public static function text($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4)
{
$enc = QRencode::factory($level, $size, $margin);
return $enc->encode($text, $outfile);
}
//----------------------------------------------------------------------
public static function raw($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4)
{
$enc = QRencode::factory($level, $size, $margin);
return $enc->encodeRAW($text, $outfile);
}
}
/* End of file qrcode.php */
/* Location: .//D/workspace/chinahighlights.com/CHT/third_party/pay/libraries/wxpay/phpqrcode/qrcode.php */

@ -0,0 +1,79 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class QRimage {
protected $ci;
public function __construct()
{
$this->ci =& get_instance();
}
//----------------------------------------------------------------------
public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE)
{
$image = self::image($frame, $pixelPerPoint, $outerFrame);
if ($filename === false) {
Header("Content-type: image/png");
ImagePng($image);
} else {
if($saveandprint===TRUE){
ImagePng($image, $filename);
header("Content-type: image/png");
ImagePng($image);
}else{
ImagePng($image, $filename);
}
}
ImageDestroy($image);
}
//----------------------------------------------------------------------
public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85)
{
$image = self::image($frame, $pixelPerPoint, $outerFrame);
if ($filename === false) {
Header("Content-type: image/jpeg");
ImageJpeg($image, null, $q);
} else {
ImageJpeg($image, $filename, $q);
}
ImageDestroy($image);
}
//----------------------------------------------------------------------
private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4)
{
$h = count($frame);
$w = strlen($frame[0]);
$imgW = $w + 2*$outerFrame;
$imgH = $h + 2*$outerFrame;
$base_image =ImageCreate($imgW, $imgH);
$col[0] = ImageColorAllocate($base_image,255,255,255);
$col[1] = ImageColorAllocate($base_image,0,0,0);
imagefill($base_image, 0, 0, $col[0]);
for($y=0; $y<$h; $y++) {
for($x=0; $x<$w; $x++) {
if ($frame[$y][$x] == '1') {
ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]);
}
}
}
$target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint);
ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH);
ImageDestroy($base_image);
return $target_image;
}
}

@ -0,0 +1,466 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class QRinput {
protected $ci;
public function __construct()
{
$this->ci =& get_instance();
}
public $items;
private $version;
private $level;
//----------------------------------------------------------------------
public function __construct($version = 0, $level = QR_ECLEVEL_L)
{
if ($version < 0 || $version > QRSPEC_VERSION_MAX || $level > QR_ECLEVEL_H) {
throw new Exception('Invalid version no');
return NULL;
}
$this->version = $version;
$this->level = $level;
}
//----------------------------------------------------------------------
public function getVersion()
{
return $this->version;
}
//----------------------------------------------------------------------
public function setVersion($version)
{
if($version < 0 || $version > QRSPEC_VERSION_MAX) {
throw new Exception('Invalid version no');
return -1;
}
$this->version = $version;
return 0;
}
//----------------------------------------------------------------------
public function getErrorCorrectionLevel()
{
return $this->level;
}
//----------------------------------------------------------------------
public function setErrorCorrectionLevel($level)
{
if($level > QR_ECLEVEL_H) {
throw new Exception('Invalid ECLEVEL');
return -1;
}
$this->level = $level;
return 0;
}
//----------------------------------------------------------------------
public function appendEntry(QRinputItem $entry)
{
$this->items[] = $entry;
}
//----------------------------------------------------------------------
public function append($mode, $size, $data)
{
try {
$entry = new QRinputItem($mode, $size, $data);
$this->items[] = $entry;
return 0;
} catch (Exception $e) {
return -1;
}
}
//----------------------------------------------------------------------
public function insertStructuredAppendHeader($size, $index, $parity)
{
if( $size > MAX_STRUCTURED_SYMBOLS ) {
throw new Exception('insertStructuredAppendHeader wrong size');
}
if( $index <= 0 || $index > MAX_STRUCTURED_SYMBOLS ) {
throw new Exception('insertStructuredAppendHeader wrong index');
}
$buf = array($size, $index, $parity);
try {
$entry = new QRinputItem(QR_MODE_STRUCTURE, 3, buf);
array_unshift($this->items, $entry);
return 0;
} catch (Exception $e) {
return -1;
}
}
//----------------------------------------------------------------------
public function calcParity()
{
$parity = 0;
foreach($this->items as $item) {
if($item->mode != QR_MODE_STRUCTURE) {
for($i=$item->size-1; $i>=0; $i--) {
$parity ^= $item->data[$i];
}
}
}
return $parity;
}
//----------------------------------------------------------------------
public static function checkModeNum($size, $data)
{
for($i=0; $i<$size; $i++) {
if((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))){
return false;
}
}
return true;
}
//----------------------------------------------------------------------
public static function estimateBitsModeNum($size)
{
$w = (int)$size / 3;
$bits = $w * 10;
switch($size - $w * 3) {
case 1:
$bits += 4;
break;
case 2:
$bits += 7;
break;
default:
break;
}
return $bits;
}
//----------------------------------------------------------------------
public static $anTable = array(
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43,
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1,
-1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1
);
//----------------------------------------------------------------------
public static function lookAnTable($c)
{
return (($c > 127)?-1:self::$anTable[$c]);
}
//----------------------------------------------------------------------
public static function checkModeAn($size, $data)
{
for($i=0; $i<$size; $i++) {
if (self::lookAnTable(ord($data[$i])) == -1) {
return false;
}
}
return true;
}
//----------------------------------------------------------------------
public static function estimateBitsModeAn($size)
{
$w = (int)($size / 2);
$bits = $w * 11;
if($size & 1) {
$bits += 6;
}
return $bits;
}
//----------------------------------------------------------------------
public static function estimateBitsMode8($size)
{
return $size * 8;
}
//----------------------------------------------------------------------
public function estimateBitsModeKanji($size)
{
return (int)(($size / 2) * 13);
}
//----------------------------------------------------------------------
public static function checkModeKanji($size, $data)
{
if($size & 1)
return false;
for($i=0; $i<$size; $i+=2) {
$val = (ord($data[$i]) << 8) | ord($data[$i+1]);
if( $val < 0x8140
|| ($val > 0x9ffc && $val < 0xe040)
|| $val > 0xebbf) {
return false;
}
}
return true;
}
/***********************************************************************
* Validation
**********************************************************************/
public static function check($mode, $size, $data)
{
if($size <= 0)
return false;
switch($mode) {
case QR_MODE_NUM: return self::checkModeNum($size, $data); break;
case QR_MODE_AN: return self::checkModeAn($size, $data); break;
case QR_MODE_KANJI: return self::checkModeKanji($size, $data); break;
case QR_MODE_8: return true; break;
case QR_MODE_STRUCTURE: return true; break;
default:
break;
}
return false;
}
//----------------------------------------------------------------------
public function estimateBitStreamSize($version)
{
$bits = 0;
foreach($this->items as $item) {
$bits += $item->estimateBitStreamSizeOfEntry($version);
}
return $bits;
}
//----------------------------------------------------------------------
public function estimateVersion()
{
$version = 0;
$prev = 0;
do {
$prev = $version;
$bits = $this->estimateBitStreamSize($prev);
$version = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level);
if ($version < 0) {
return -1;
}
} while ($version > $prev);
return $version;
}
//----------------------------------------------------------------------
public static function lengthOfCode($mode, $version, $bits)
{
$payload = $bits - 4 - QRspec::lengthIndicator($mode, $version);
switch($mode) {
case QR_MODE_NUM:
$chunks = (int)($payload / 10);
$remain = $payload - $chunks * 10;
$size = $chunks * 3;
if($remain >= 7) {
$size += 2;
} else if($remain >= 4) {
$size += 1;
}
break;
case QR_MODE_AN:
$chunks = (int)($payload / 11);
$remain = $payload - $chunks * 11;
$size = $chunks * 2;
if($remain >= 6)
$size++;
break;
case QR_MODE_8:
$size = (int)($payload / 8);
break;
case QR_MODE_KANJI:
$size = (int)(($payload / 13) * 2);
break;
case QR_MODE_STRUCTURE:
$size = (int)($payload / 8);
break;
default:
$size = 0;
break;
}
$maxsize = QRspec::maximumWords($mode, $version);
if($size < 0) $size = 0;
if($size > $maxsize) $size = $maxsize;
return $size;
}
//----------------------------------------------------------------------
public function createBitStream()
{
$total = 0;
foreach($this->items as $item) {
$bits = $item->encodeBitStream($this->version);
if($bits < 0)
return -1;
$total += $bits;
}
return $total;
}
//----------------------------------------------------------------------
public function convertData()
{
$ver = $this->estimateVersion();
if($ver > $this->getVersion()) {
$this->setVersion($ver);
}
for(;;) {
$bits = $this->createBitStream();
if($bits < 0)
return -1;
$ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level);
if($ver < 0) {
throw new Exception('WRONG VERSION');
return -1;
} else if($ver > $this->getVersion()) {
$this->setVersion($ver);
} else {
break;
}
}
return 0;
}
//----------------------------------------------------------------------
public function appendPaddingBit(&$bstream)
{
$bits = $bstream->size();
$maxwords = QRspec::getDataLength($this->version, $this->level);
$maxbits = $maxwords * 8;
if ($maxbits == $bits) {
return 0;
}
if ($maxbits - $bits < 5) {
return $bstream->appendNum($maxbits - $bits, 0);
}
$bits += 4;
$words = (int)(($bits + 7) / 8);
$padding = new QRbitstream();
$ret = $padding->appendNum($words * 8 - $bits + 4, 0);
if($ret < 0)
return $ret;
$padlen = $maxwords - $words;
if($padlen > 0) {
$padbuf = array();
for($i=0; $i<$padlen; $i++) {
$padbuf[$i] = ($i&1)?0x11:0xec;
}
$ret = $padding->appendBytes($padlen, $padbuf);
if($ret < 0)
return $ret;
}
$ret = $bstream->append($padding);
return $ret;
}
//----------------------------------------------------------------------
public function mergeBitStream()
{
if($this->convertData() < 0) {
return null;
}
$bstream = new QRbitstream();
foreach($this->items as $item) {
$ret = $bstream->append($item->bstream);
if($ret < 0) {
return null;
}
}
return $bstream;
}
//----------------------------------------------------------------------
public function getBitStream()
{
$bstream = $this->mergeBitStream();
if($bstream == null) {
return null;
}
$ret = $this->appendPaddingBit($bstream);
if($ret < 0) {
return null;
}
return $bstream;
}
//----------------------------------------------------------------------
public function getByteStream()
{
$bstream = $this->getBitStream();
if($bstream == null) {
return null;
}
return $bstream->toByte();
}
}
/* End of file libraryName.php */
/* Location: ./application/libraries/libraryName.php */

@ -0,0 +1,256 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class QRinputItem {
protected $ci;
public function __construct()
{
$this->ci =& get_instance();
}
public $mode;
public $size;
public $data;
public $bstream;
public function __construct($mode, $size, $data, $bstream = null)
{
$setData = array_slice($data, 0, $size);
if (count($setData) < $size) {
$setData = array_merge($setData, array_fill(0,$size-count($setData),0));
}
if(!QRinput::check($mode, $size, $setData)) {
throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData));
return null;
}
$this->mode = $mode;
$this->size = $size;
$this->data = $setData;
$this->bstream = $bstream;
}
//----------------------------------------------------------------------
public function encodeModeNum($version)
{
try {
$words = (int)($this->size / 3);
$bs = new QRbitstream();
$val = 0x1;
$bs->appendNum(4, $val);
$bs->appendNum(QRspec::lengthIndicator(QR_MODE_NUM, $version), $this->size);
for($i=0; $i<$words; $i++) {
$val = (ord($this->data[$i*3 ]) - ord('0')) * 100;
$val += (ord($this->data[$i*3+1]) - ord('0')) * 10;
$val += (ord($this->data[$i*3+2]) - ord('0'));
$bs->appendNum(10, $val);
}
if($this->size - $words * 3 == 1) {
$val = ord($this->data[$words*3]) - ord('0');
$bs->appendNum(4, $val);
} else if($this->size - $words * 3 == 2) {
$val = (ord($this->data[$words*3 ]) - ord('0')) * 10;
$val += (ord($this->data[$words*3+1]) - ord('0'));
$bs->appendNum(7, $val);
}
$this->bstream = $bs;
return 0;
} catch (Exception $e) {
return -1;
}
}
//----------------------------------------------------------------------
public function encodeModeAn($version)
{
try {
$words = (int)($this->size / 2);
$bs = new QRbitstream();
$bs->appendNum(4, 0x02);
$bs->appendNum(QRspec::lengthIndicator(QR_MODE_AN, $version), $this->size);
for($i=0; $i<$words; $i++) {
$val = (int)QRinput::lookAnTable(ord($this->data[$i*2 ])) * 45;
$val += (int)QRinput::lookAnTable(ord($this->data[$i*2+1]));
$bs->appendNum(11, $val);
}
if($this->size & 1) {
$val = QRinput::lookAnTable(ord($this->data[$words * 2]));
$bs->appendNum(6, $val);
}
$this->bstream = $bs;
return 0;
} catch (Exception $e) {
return -1;
}
}
//----------------------------------------------------------------------
public function encodeMode8($version)
{
try {
$bs = new QRbitstream();
$bs->appendNum(4, 0x4);
$bs->appendNum(QRspec::lengthIndicator(QR_MODE_8, $version), $this->size);
for($i=0; $i<$this->size; $i++) {
$bs->appendNum(8, ord($this->data[$i]));
}
$this->bstream = $bs;
return 0;
} catch (Exception $e) {
return -1;
}
}
//----------------------------------------------------------------------
public function encodeModeKanji($version)
{
try {
$bs = new QRbitrtream();
$bs->appendNum(4, 0x8);
$bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int)($this->size / 2));
for($i=0; $i<$this->size; $i+=2) {
$val = (ord($this->data[$i]) << 8) | ord($this->data[$i+1]);
if($val <= 0x9ffc) {
$val -= 0x8140;
} else {
$val -= 0xc140;
}
$h = ($val >> 8) * 0xc0;
$val = ($val & 0xff) + $h;
$bs->appendNum(13, $val);
}
$this->bstream = $bs;
return 0;
} catch (Exception $e) {
return -1;
}
}
//----------------------------------------------------------------------
public function encodeModeStructure()
{
try {
$bs = new QRbitstream();
$bs->appendNum(4, 0x03);
$bs->appendNum(4, ord($this->data[1]) - 1);
$bs->appendNum(4, ord($this->data[0]) - 1);
$bs->appendNum(8, ord($this->data[2]));
$this->bstream = $bs;
return 0;
} catch (Exception $e) {
return -1;
}
}
//----------------------------------------------------------------------
public function estimateBitStreamSizeOfEntry($version)
{
$bits = 0;
if($version == 0)
$version = 1;
switch($this->mode) {
case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break;
case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break;
case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break;
case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size);break;
case QR_MODE_STRUCTURE: return STRUCTURE_HEADER_BITS;
default:
return 0;
}
$l = QRspec::lengthIndicator($this->mode, $version);
$m = 1 << $l;
$num = (int)(($this->size + $m - 1) / $m);
$bits += $num * (4 + $l);
return $bits;
}
//----------------------------------------------------------------------
public function encodeBitStream($version)
{
try {
unset($this->bstream);
$words = QRspec::maximumWords($this->mode, $version);
if($this->size > $words) {
$st1 = new QRinputItem($this->mode, $words, $this->data);
$st2 = new QRinputItem($this->mode, $this->size - $words, array_slice($this->data, $words));
$st1->encodeBitStream($version);
$st2->encodeBitStream($version);
$this->bstream = new QRbitstream();
$this->bstream->append($st1->bstream);
$this->bstream->append($st2->bstream);
unset($st1);
unset($st2);
} else {
$ret = 0;
switch($this->mode) {
case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break;
case QR_MODE_AN: $ret = $this->encodeModeAn($version); break;
case QR_MODE_8: $ret = $this->encodeMode8($version); break;
case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version);break;
case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break;
default:
break;
}
if($ret < 0)
return -1;
}
return $this->bstream->size();
} catch (Exception $e) {
return -1;
}
}
};
/* End of file libraryName.php */
/* Location: ./application/libraries/libraryName.php */

@ -0,0 +1,167 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class QRrsItem {
protected $ci;
public function __construct()
{
$this->ci =& get_instance();
}
public $mm; // Bits per symbol
public $nn; // Symbols per block (= (1<<mm)-1)
public $alpha_to = array(); // log lookup table
public $index_of = array(); // Antilog lookup table
public $genpoly = array(); // Generator polynomial
public $nroots; // Number of generator roots = number of parity symbols
public $fcr; // First consecutive root, index form
public $prim; // Primitive element, index form
public $iprim; // prim-th root of 1, index form
public $pad; // Padding bytes in shortened block
public $gfpoly;
//----------------------------------------------------------------------
public function modnn($x)
{
while ($x >= $this->nn) {
$x -= $this->nn;
$x = ($x >> $this->mm) + ($x & $this->nn);
}
return $x;
}
//----------------------------------------------------------------------
public static function init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad)
{
// Common code for intializing a Reed-Solomon control block (char or int symbols)
// Copyright 2004 Phil Karn, KA9Q
// May be used under the terms of the GNU Lesser General Public License (LGPL)
$rs = null;
// Check parameter ranges
if($symsize < 0 || $symsize > 8) return $rs;
if($fcr < 0 || $fcr >= (1<<$symsize)) return $rs;
if($prim <= 0 || $prim >= (1<<$symsize)) return $rs;
if($nroots < 0 || $nroots >= (1<<$symsize)) return $rs; // Can't have more roots than symbol values!
if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding
$rs = new QRrsItem();
$rs->mm = $symsize;
$rs->nn = (1<<$symsize)-1;
$rs->pad = $pad;
$rs->alpha_to = array_fill(0, $rs->nn+1, 0);
$rs->index_of = array_fill(0, $rs->nn+1, 0);
// PHP style macro replacement ;)
$NN =& $rs->nn;
$A0 =& $NN;
// Generate Galois field lookup tables
$rs->index_of[0] = $A0; // log(zero) = -inf
$rs->alpha_to[$A0] = 0; // alpha**-inf = 0
$sr = 1;
for($i=0; $i<$rs->nn; $i++) {
$rs->index_of[$sr] = $i;
$rs->alpha_to[$i] = $sr;
$sr <<= 1;
if($sr & (1<<$symsize)) {
$sr ^= $gfpoly;
}
$sr &= $rs->nn;
}
if($sr != 1){
// field generator polynomial is not primitive!
$rs = NULL;
return $rs;
}
/* Form RS code generator polynomial from its roots */
$rs->genpoly = array_fill(0, $nroots+1, 0);
$rs->fcr = $fcr;
$rs->prim = $prim;
$rs->nroots = $nroots;
$rs->gfpoly = $gfpoly;
/* Find prim-th root of 1, used in decoding */
for($iprim=1;($iprim % $prim) != 0;$iprim += $rs->nn)
; // intentional empty-body loop!
$rs->iprim = (int)($iprim / $prim);
$rs->genpoly[0] = 1;
for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) {
$rs->genpoly[$i+1] = 1;
// Multiply rs->genpoly[] by @**(root + x)
for ($j = $i; $j > 0; $j--) {
if ($rs->genpoly[$j] != 0) {
$rs->genpoly[$j] = $rs->genpoly[$j-1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)];
} else {
$rs->genpoly[$j] = $rs->genpoly[$j-1];
}
}
// rs->genpoly[0] can never be zero
$rs->genpoly[0] = $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[0]] + $root)];
}
// convert rs->genpoly[] to index form for quicker encoding
for ($i = 0; $i <= $nroots; $i++)
$rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]];
return $rs;
}
//----------------------------------------------------------------------
public function encode_rs_char($data, &$parity)
{
$MM =& $this->mm;
$NN =& $this->nn;
$ALPHA_TO =& $this->alpha_to;
$INDEX_OF =& $this->index_of;
$GENPOLY =& $this->genpoly;
$NROOTS =& $this->nroots;
$FCR =& $this->fcr;
$PRIM =& $this->prim;
$IPRIM =& $this->iprim;
$PAD =& $this->pad;
$A0 =& $NN;
$parity = array_fill(0, $NROOTS, 0);
for($i=0; $i< ($NN-$NROOTS-$PAD); $i++) {
$feedback = $INDEX_OF[$data[$i] ^ $parity[0]];
if($feedback != $A0) {
// feedback term is non-zero
// This line is unnecessary when GENPOLY[NROOTS] is unity, as it must
// always be for the polynomials constructed by init_rs()
$feedback = $this->modnn($NN - $GENPOLY[$NROOTS] + $feedback);
for($j=1;$j<$NROOTS;$j++) {
$parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS-$j])];
}
}
// Shift
array_shift($parity);
if($feedback != $A0) {
array_push($parity, $ALPHA_TO[$this->modnn($feedback + $GENPOLY[0])]);
} else {
array_push($parity, 0);
}
}
}
}
/* End of file */
/* Location: ./application/libraries/ */

@ -0,0 +1,561 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class QRspec {
protected $ci;
public function __construct()
{
$this->ci =& get_instance();
}
public static $capacity = array(
array( 0, 0, 0, array( 0, 0, 0, 0)),
array( 21, 26, 0, array( 7, 10, 13, 17)), // 1
array( 25, 44, 7, array( 10, 16, 22, 28)),
array( 29, 70, 7, array( 15, 26, 36, 44)),
array( 33, 100, 7, array( 20, 36, 52, 64)),
array( 37, 134, 7, array( 26, 48, 72, 88)), // 5
array( 41, 172, 7, array( 36, 64, 96, 112)),
array( 45, 196, 0, array( 40, 72, 108, 130)),
array( 49, 242, 0, array( 48, 88, 132, 156)),
array( 53, 292, 0, array( 60, 110, 160, 192)),
array( 57, 346, 0, array( 72, 130, 192, 224)), //10
array( 61, 404, 0, array( 80, 150, 224, 264)),
array( 65, 466, 0, array( 96, 176, 260, 308)),
array( 69, 532, 0, array( 104, 198, 288, 352)),
array( 73, 581, 3, array( 120, 216, 320, 384)),
array( 77, 655, 3, array( 132, 240, 360, 432)), //15
array( 81, 733, 3, array( 144, 280, 408, 480)),
array( 85, 815, 3, array( 168, 308, 448, 532)),
array( 89, 901, 3, array( 180, 338, 504, 588)),
array( 93, 991, 3, array( 196, 364, 546, 650)),
array( 97, 1085, 3, array( 224, 416, 600, 700)), //20
array(101, 1156, 4, array( 224, 442, 644, 750)),
array(105, 1258, 4, array( 252, 476, 690, 816)),
array(109, 1364, 4, array( 270, 504, 750, 900)),
array(113, 1474, 4, array( 300, 560, 810, 960)),
array(117, 1588, 4, array( 312, 588, 870, 1050)), //25
array(121, 1706, 4, array( 336, 644, 952, 1110)),
array(125, 1828, 4, array( 360, 700, 1020, 1200)),
array(129, 1921, 3, array( 390, 728, 1050, 1260)),
array(133, 2051, 3, array( 420, 784, 1140, 1350)),
array(137, 2185, 3, array( 450, 812, 1200, 1440)), //30
array(141, 2323, 3, array( 480, 868, 1290, 1530)),
array(145, 2465, 3, array( 510, 924, 1350, 1620)),
array(149, 2611, 3, array( 540, 980, 1440, 1710)),
array(153, 2761, 3, array( 570, 1036, 1530, 1800)),
array(157, 2876, 0, array( 570, 1064, 1590, 1890)), //35
array(161, 3034, 0, array( 600, 1120, 1680, 1980)),
array(165, 3196, 0, array( 630, 1204, 1770, 2100)),
array(169, 3362, 0, array( 660, 1260, 1860, 2220)),
array(173, 3532, 0, array( 720, 1316, 1950, 2310)),
array(177, 3706, 0, array( 750, 1372, 2040, 2430)) //40
);
//----------------------------------------------------------------------
public static function getDataLength($version, $level)
{
return self::$capacity[$version][QRCAP_WORDS] - self::$capacity[$version][QRCAP_EC][$level];
}
//----------------------------------------------------------------------
public static function getECCLength($version, $level)
{
return self::$capacity[$version][QRCAP_EC][$level];
}
//----------------------------------------------------------------------
public static function getWidth($version)
{
return self::$capacity[$version][QRCAP_WIDTH];
}
//----------------------------------------------------------------------
public static function getRemainder($version)
{
return self::$capacity[$version][QRCAP_REMINDER];
}
//----------------------------------------------------------------------
public static function getMinimumVersion($size, $level)
{
for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) {
$words = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level];
if($words >= $size)
return $i;
}
return -1;
}
//######################################################################
public static $lengthTableBits = array(
array(10, 12, 14),
array( 9, 11, 13),
array( 8, 16, 16),
array( 8, 10, 12)
);
//----------------------------------------------------------------------
public static function lengthIndicator($mode, $version)
{
if ($mode == QR_MODE_STRUCTURE)
return 0;
if ($version <= 9) {
$l = 0;
} else if ($version <= 26) {
$l = 1;
} else {
$l = 2;
}
return self::$lengthTableBits[$mode][$l];
}
//----------------------------------------------------------------------
public static function maximumWords($mode, $version)
{
if($mode == QR_MODE_STRUCTURE)
return 3;
if($version <= 9) {
$l = 0;
} else if($version <= 26) {
$l = 1;
} else {
$l = 2;
}
$bits = self::$lengthTableBits[$mode][$l];
$words = (1 << $bits) - 1;
if($mode == QR_MODE_KANJI) {
$words *= 2; // the number of bytes is required
}
return $words;
}
// Error correction code -----------------------------------------------
// Table of the error correction code (Reed-Solomon block)
// See Table 12-16 (pp.30-36), JIS X0510:2004.
public static $eccTable = array(
array(array( 0, 0), array( 0, 0), array( 0, 0), array( 0, 0)),
array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), // 1
array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)),
array(array( 1, 0), array( 1, 0), array( 2, 0), array( 2, 0)),
array(array( 1, 0), array( 2, 0), array( 2, 0), array( 4, 0)),
array(array( 1, 0), array( 2, 0), array( 2, 2), array( 2, 2)), // 5
array(array( 2, 0), array( 4, 0), array( 4, 0), array( 4, 0)),
array(array( 2, 0), array( 4, 0), array( 2, 4), array( 4, 1)),
array(array( 2, 0), array( 2, 2), array( 4, 2), array( 4, 2)),
array(array( 2, 0), array( 3, 2), array( 4, 4), array( 4, 4)),
array(array( 2, 2), array( 4, 1), array( 6, 2), array( 6, 2)), //10
array(array( 4, 0), array( 1, 4), array( 4, 4), array( 3, 8)),
array(array( 2, 2), array( 6, 2), array( 4, 6), array( 7, 4)),
array(array( 4, 0), array( 8, 1), array( 8, 4), array(12, 4)),
array(array( 3, 1), array( 4, 5), array(11, 5), array(11, 5)),
array(array( 5, 1), array( 5, 5), array( 5, 7), array(11, 7)), //15
array(array( 5, 1), array( 7, 3), array(15, 2), array( 3, 13)),
array(array( 1, 5), array(10, 1), array( 1, 15), array( 2, 17)),
array(array( 5, 1), array( 9, 4), array(17, 1), array( 2, 19)),
array(array( 3, 4), array( 3, 11), array(17, 4), array( 9, 16)),
array(array( 3, 5), array( 3, 13), array(15, 5), array(15, 10)), //20
array(array( 4, 4), array(17, 0), array(17, 6), array(19, 6)),
array(array( 2, 7), array(17, 0), array( 7, 16), array(34, 0)),
array(array( 4, 5), array( 4, 14), array(11, 14), array(16, 14)),
array(array( 6, 4), array( 6, 14), array(11, 16), array(30, 2)),
array(array( 8, 4), array( 8, 13), array( 7, 22), array(22, 13)), //25
array(array(10, 2), array(19, 4), array(28, 6), array(33, 4)),
array(array( 8, 4), array(22, 3), array( 8, 26), array(12, 28)),
array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)),
array(array( 7, 7), array(21, 7), array( 1, 37), array(19, 26)),
array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), //30
array(array(13, 3), array( 2, 29), array(42, 1), array(23, 28)),
array(array(17, 0), array(10, 23), array(10, 35), array(19, 35)),
array(array(17, 1), array(14, 21), array(29, 19), array(11, 46)),
array(array(13, 6), array(14, 23), array(44, 7), array(59, 1)),
array(array(12, 7), array(12, 26), array(39, 14), array(22, 41)), //35
array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)),
array(array(17, 4), array(29, 14), array(49, 10), array(24, 46)),
array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)),
array(array(20, 4), array(40, 7), array(43, 22), array(10, 67)),
array(array(19, 6), array(18, 31), array(34, 34), array(20, 61)),//40
);
//----------------------------------------------------------------------
// CACHEABLE!!!
public static function getEccSpec($version, $level, array &$spec)
{
if (count($spec) < 5) {
$spec = array(0,0,0,0,0);
}
$b1 = self::$eccTable[$version][$level][0];
$b2 = self::$eccTable[$version][$level][1];
$data = self::getDataLength($version, $level);
$ecc = self::getECCLength($version, $level);
if($b2 == 0) {
$spec[0] = $b1;
$spec[1] = (int)($data / $b1);
$spec[2] = (int)($ecc / $b1);
$spec[3] = 0;
$spec[4] = 0;
} else {
$spec[0] = $b1;
$spec[1] = (int)($data / ($b1 + $b2));
$spec[2] = (int)($ecc / ($b1 + $b2));
$spec[3] = $b2;
$spec[4] = $spec[1] + 1;
}
}
// Alignment pattern ---------------------------------------------------
// Positions of alignment patterns.
// This array includes only the second and the third position of the
// alignment patterns. Rest of them can be calculated from the distance
// between them.
// See Table 1 in Appendix E (pp.71) of JIS X0510:2004.
public static $alignmentPattern = array(
array( 0, 0),
array( 0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0), // 1- 5
array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10
array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), //11-15
array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), //16-20
array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), //21-25
array(30, 58), array(34, 62), array(26, 50), array(30, 54), array(26, 52), //26-30
array(30, 56), array(34, 60), array(30, 58), array(34, 62), array(30, 54), //31-35
array(24, 50), array(28, 54), array(32, 58), array(26, 54), array(30, 58), //35-40
);
/** --------------------------------------------------------------------
* Put an alignment marker.
* @param frame
* @param width
* @param ox,oy center coordinate of the pattern
*/
public static function putAlignmentMarker(array &$frame, $ox, $oy)
{
$finder = array(
"\xa1\xa1\xa1\xa1\xa1",
"\xa1\xa0\xa0\xa0\xa1",
"\xa1\xa0\xa1\xa0\xa1",
"\xa1\xa0\xa0\xa0\xa1",
"\xa1\xa1\xa1\xa1\xa1"
);
$yStart = $oy-2;
$xStart = $ox-2;
for($y=0; $y<5; $y++) {
QRstr::set($frame, $xStart, $yStart+$y, $finder[$y]);
}
}
//----------------------------------------------------------------------
public static function putAlignmentPattern($version, &$frame, $width)
{
if($version < 2)
return;
$d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0];
if($d < 0) {
$w = 2;
} else {
$w = (int)(($width - self::$alignmentPattern[$version][0]) / $d + 2);
}
if($w * $w - 3 == 1) {
$x = self::$alignmentPattern[$version][0];
$y = self::$alignmentPattern[$version][0];
self::putAlignmentMarker($frame, $x, $y);
return;
}
$cx = self::$alignmentPattern[$version][0];
for($x=1; $x<$w - 1; $x++) {
self::putAlignmentMarker($frame, 6, $cx);
self::putAlignmentMarker($frame, $cx, 6);
$cx += $d;
}
$cy = self::$alignmentPattern[$version][0];
for($y=0; $y<$w-1; $y++) {
$cx = self::$alignmentPattern[$version][0];
for($x=0; $x<$w-1; $x++) {
self::putAlignmentMarker($frame, $cx, $cy);
$cx += $d;
}
$cy += $d;
}
}
// Version information pattern -----------------------------------------
// Version information pattern (BCH coded).
// See Table 1 in Appendix D (pp.68) of JIS X0510:2004.
// size: [QRSPEC_VERSION_MAX - 6]
public static $versionPattern = array(
0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d,
0x0f928, 0x10b78, 0x1145d, 0x12a17, 0x13532, 0x149a6, 0x15683, 0x168c9,
0x177ec, 0x18ec4, 0x191e1, 0x1afab, 0x1b08e, 0x1cc1a, 0x1d33f, 0x1ed75,
0x1f250, 0x209d5, 0x216f0, 0x228ba, 0x2379f, 0x24b0b, 0x2542e, 0x26a64,
0x27541, 0x28c69
);
//----------------------------------------------------------------------
public static function getVersionPattern($version)
{
if($version < 7 || $version > QRSPEC_VERSION_MAX)
return 0;
return self::$versionPattern[$version -7];
}
// Format information --------------------------------------------------
// See calcFormatInfo in tests/test_qrspec.c (orginal qrencode c lib)
public static $formatInfo = array(
array(0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976),
array(0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0),
array(0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed),
array(0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b)
);
public static function getFormatInfo($mask, $level)
{
if($mask < 0 || $mask > 7)
return 0;
if($level < 0 || $level > 3)
return 0;
return self::$formatInfo[$level][$mask];
}
// Frame ---------------------------------------------------------------
// Cache of initial frames.
public static $frames = array();
/** --------------------------------------------------------------------
* Put a finder pattern.
* @param frame
* @param width
* @param ox,oy upper-left coordinate of the pattern
*/
public static function putFinderPattern(&$frame, $ox, $oy)
{
$finder = array(
"\xc1\xc1\xc1\xc1\xc1\xc1\xc1",
"\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
"\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
"\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
"\xc1\xc0\xc1\xc1\xc1\xc0\xc1",
"\xc1\xc0\xc0\xc0\xc0\xc0\xc1",
"\xc1\xc1\xc1\xc1\xc1\xc1\xc1"
);
for($y=0; $y<7; $y++) {
QRstr::set($frame, $ox, $oy+$y, $finder[$y]);
}
}
//----------------------------------------------------------------------
public static function createFrame($version)
{
$width = self::$capacity[$version][QRCAP_WIDTH];
$frameLine = str_repeat ("\0", $width);
$frame = array_fill(0, $width, $frameLine);
// Finder pattern
self::putFinderPattern($frame, 0, 0);
self::putFinderPattern($frame, $width - 7, 0);
self::putFinderPattern($frame, 0, $width - 7);
// Separator
$yOffset = $width - 7;
for($y=0; $y<7; $y++) {
$frame[$y][7] = "\xc0";
$frame[$y][$width - 8] = "\xc0";
$frame[$yOffset][7] = "\xc0";
$yOffset++;
}
$setPattern = str_repeat("\xc0", 8);
QRstr::set($frame, 0, 7, $setPattern);
QRstr::set($frame, $width-8, 7, $setPattern);
QRstr::set($frame, 0, $width - 8, $setPattern);
// Format info
$setPattern = str_repeat("\x84", 9);
QRstr::set($frame, 0, 8, $setPattern);
QRstr::set($frame, $width - 8, 8, $setPattern, 8);
$yOffset = $width - 8;
for($y=0; $y<8; $y++,$yOffset++) {
$frame[$y][8] = "\x84";
$frame[$yOffset][8] = "\x84";
}
// Timing pattern
for($i=1; $i<$width-15; $i++) {
$frame[6][7+$i] = chr(0x90 | ($i & 1));
$frame[7+$i][6] = chr(0x90 | ($i & 1));
}
// Alignment pattern
self::putAlignmentPattern($version, $frame, $width);
// Version information
if($version >= 7) {
$vinf = self::getVersionPattern($version);
$v = $vinf;
for($x=0; $x<6; $x++) {
for($y=0; $y<3; $y++) {
$frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1));
$v = $v >> 1;
}
}
$v = $vinf;
for($y=0; $y<6; $y++) {
for($x=0; $x<3; $x++) {
$frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1));
$v = $v >> 1;
}
}
}
// and a little bit...
$frame[$width - 8][8] = "\x81";
return $frame;
}
//----------------------------------------------------------------------
public static function debug($frame, $binary_mode = false)
{
if ($binary_mode) {
foreach ($frame as &$frameLine) {
$frameLine = join('<span class="m">&nbsp;&nbsp;</span>', explode('0', $frameLine));
$frameLine = join('&#9608;&#9608;', explode('1', $frameLine));
}
?>
<style>
.m { background-color: white; }
</style>
<?php
echo '<pre><tt><br/ ><br/ ><br/ >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
echo join("<br/ >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;", $frame);
echo '</tt></pre><br/ ><br/ ><br/ ><br/ ><br/ ><br/ >';
} else {
foreach ($frame as &$frameLine) {
$frameLine = join('<span class="m">&nbsp;</span>', explode("\xc0", $frameLine));
$frameLine = join('<span class="m">&#9618;</span>', explode("\xc1", $frameLine));
$frameLine = join('<span class="p">&nbsp;</span>', explode("\xa0", $frameLine));
$frameLine = join('<span class="p">&#9618;</span>', explode("\xa1", $frameLine));
$frameLine = join('<span class="s">&#9671;</span>', explode("\x84", $frameLine)); //format 0
$frameLine = join('<span class="s">&#9670;</span>', explode("\x85", $frameLine)); //format 1
$frameLine = join('<span class="x">&#9762;</span>', explode("\x81", $frameLine)); //special bit
$frameLine = join('<span class="c">&nbsp;</span>', explode("\x90", $frameLine)); //clock 0
$frameLine = join('<span class="c">&#9719;</span>', explode("\x91", $frameLine)); //clock 1
$frameLine = join('<span class="f">&nbsp;</span>', explode("\x88", $frameLine)); //version
$frameLine = join('<span class="f">&#9618;</span>', explode("\x89", $frameLine)); //version
$frameLine = join('&#9830;', explode("\x01", $frameLine));
$frameLine = join('&#8901;', explode("\0", $frameLine));
}
?>
<style>
.p { background-color: yellow; }
.m { background-color: #00FF00; }
.s { background-color: #FF0000; }
.c { background-color: aqua; }
.x { background-color: pink; }
.f { background-color: gold; }
</style>
<?php
echo "<pre><tt>";
echo join("<br/ >", $frame);
echo "</tt></pre>";
}
}
//----------------------------------------------------------------------
public static function serial($frame)
{
return gzcompress(join("\n", $frame), 9);
}
//----------------------------------------------------------------------
public static function unserial($code)
{
return explode("\n", gzuncompress($code));
}
//----------------------------------------------------------------------
public static function newFrame($version)
{
if($version < 1 || $version > QRSPEC_VERSION_MAX)
return null;
if(!isset(self::$frames[$version])) {
$fileName = QR_CACHE_DIR.'frame_'.$version.'.dat';
if (QR_CACHEABLE) {
if (file_exists($fileName)) {
self::$frames[$version] = self::unserial(file_get_contents($fileName));
} else {
self::$frames[$version] = self::createFrame($version);
file_put_contents($fileName, self::serial(self::$frames[$version]));
}
} else {
self::$frames[$version] = self::createFrame($version);
}
}
if(is_null(self::$frames[$version]))
return null;
return self::$frames[$version];
}
//----------------------------------------------------------------------
public static function rsBlockNum($spec) { return $spec[0] + $spec[3]; }
public static function rsBlockNum1($spec) { return $spec[0]; }
public static function rsDataCodes1($spec) { return $spec[1]; }
public static function rsEccCodes1($spec) { return $spec[2]; }
public static function rsBlockNum2($spec) { return $spec[3]; }
public static function rsDataCodes2($spec) { return $spec[4]; }
public static function rsEccCodes2($spec) { return $spec[2]; }
public static function rsDataLength($spec) { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]); }
public static function rsEccLength($spec) { return ($spec[0] + $spec[3]) * $spec[2]; }
}

@ -0,0 +1,293 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class QRsplit {
protected $ci;
public function __construct()
{
$this->ci =& get_instance();
}
public $dataStr = '';
public $input;
public $modeHint;
//----------------------------------------------------------------------
public function __construct($dataStr, $input, $modeHint)
{
$this->dataStr = $dataStr;
$this->input = $input;
$this->modeHint = $modeHint;
}
//----------------------------------------------------------------------
public static function isdigitat($str, $pos)
{
if ($pos >= strlen($str))
return false;
return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9')));
}
//----------------------------------------------------------------------
public static function isalnumat($str, $pos)
{
if ($pos >= strlen($str))
return false;
return (QRinput::lookAnTable(ord($str[$pos])) >= 0);
}
//----------------------------------------------------------------------
public function identifyMode($pos)
{
if ($pos >= strlen($this->dataStr))
return QR_MODE_NUL;
$c = $this->dataStr[$pos];
if(self::isdigitat($this->dataStr, $pos)) {
return QR_MODE_NUM;
} else if(self::isalnumat($this->dataStr, $pos)) {
return QR_MODE_AN;
} else if($this->modeHint == QR_MODE_KANJI) {
if ($pos+1 < strlen($this->dataStr))
{
$d = $this->dataStr[$pos+1];
$word = (ord($c) << 8) | ord($d);
if(($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) {
return QR_MODE_KANJI;
}
}
}
return QR_MODE_8;
}
//----------------------------------------------------------------------
public function eatNum()
{
$ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion());
$p = 0;
while(self::isdigitat($this->dataStr, $p)) {
$p++;
}
$run = $p;
$mode = $this->identifyMode($p);
if($mode == QR_MODE_8) {
$dif = QRinput::estimateBitsModeNum($run) + 4 + $ln
+ QRinput::estimateBitsMode8(1) // + 4 + l8
- QRinput::estimateBitsMode8($run + 1); // - 4 - l8
if($dif > 0) {
return $this->eat8();
}
}
if($mode == QR_MODE_AN) {
$dif = QRinput::estimateBitsModeNum($run) + 4 + $ln
+ QRinput::estimateBitsModeAn(1) // + 4 + la
- QRinput::estimateBitsModeAn($run + 1);// - 4 - la
if($dif > 0) {
return $this->eatAn();
}
}
$ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr));
if($ret < 0)
return -1;
return $run;
}
//----------------------------------------------------------------------
public function eatAn()
{
$la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion());
$ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion());
$p = 0;
while(self::isalnumat($this->dataStr, $p)) {
if(self::isdigitat($this->dataStr, $p)) {
$q = $p;
while(self::isdigitat($this->dataStr, $q)) {
$q++;
}
$dif = QRinput::estimateBitsModeAn($p) // + 4 + la
+ QRinput::estimateBitsModeNum($q - $p) + 4 + $ln
- QRinput::estimateBitsModeAn($q); // - 4 - la
if($dif < 0) {
break;
} else {
$p = $q;
}
} else {
$p++;
}
}
$run = $p;
if(!self::isalnumat($this->dataStr, $p)) {
$dif = QRinput::estimateBitsModeAn($run) + 4 + $la
+ QRinput::estimateBitsMode8(1) // + 4 + l8
- QRinput::estimateBitsMode8($run + 1); // - 4 - l8
if($dif > 0) {
return $this->eat8();
}
}
$ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr));
if($ret < 0)
return -1;
return $run;
}
//----------------------------------------------------------------------
public function eatKanji()
{
$p = 0;
while($this->identifyMode($p) == QR_MODE_KANJI) {
$p += 2;
}
$ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr));
if($ret < 0)
return -1;
return $run;
}
//----------------------------------------------------------------------
public function eat8()
{
$la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion());
$ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion());
$p = 1;
$dataStrLen = strlen($this->dataStr);
while($p < $dataStrLen) {
$mode = $this->identifyMode($p);
if($mode == QR_MODE_KANJI) {
break;
}
if($mode == QR_MODE_NUM) {
$q = $p;
while(self::isdigitat($this->dataStr, $q)) {
$q++;
}
$dif = QRinput::estimateBitsMode8($p) // + 4 + l8
+ QRinput::estimateBitsModeNum($q - $p) + 4 + $ln
- QRinput::estimateBitsMode8($q); // - 4 - l8
if($dif < 0) {
break;
} else {
$p = $q;
}
} else if($mode == QR_MODE_AN) {
$q = $p;
while(self::isalnumat($this->dataStr, $q)) {
$q++;
}
$dif = QRinput::estimateBitsMode8($p) // + 4 + l8
+ QRinput::estimateBitsModeAn($q - $p) + 4 + $la
- QRinput::estimateBitsMode8($q); // - 4 - l8
if($dif < 0) {
break;
} else {
$p = $q;
}
} else {
$p++;
}
}
$run = $p;
$ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr));
if($ret < 0)
return -1;
return $run;
}
//----------------------------------------------------------------------
public function splitString()
{
while (strlen($this->dataStr) > 0)
{
if($this->dataStr == '')
return 0;
$mode = $this->identifyMode(0);
switch ($mode) {
case QR_MODE_NUM: $length = $this->eatNum(); break;
case QR_MODE_AN: $length = $this->eatAn(); break;
case QR_MODE_KANJI:
if ($hint == QR_MODE_KANJI)
$length = $this->eatKanji();
else $length = $this->eat8();
break;
default: $length = $this->eat8(); break;
}
if($length == 0) return 0;
if($length < 0) return -1;
$this->dataStr = substr($this->dataStr, $length);
}
}
//----------------------------------------------------------------------
public function toUpper()
{
$stringLen = strlen($this->dataStr);
$p = 0;
while ($p<$stringLen) {
$mode = self::identifyMode(substr($this->dataStr, $p), $this->modeHint);
if($mode == QR_MODE_KANJI) {
$p += 2;
} else {
if (ord($this->dataStr[$p]) >= ord('a') && ord($this->dataStr[$p]) <= ord('z')) {
$this->dataStr[$p] = chr(ord($this->dataStr[$p]) - 32);
}
$p++;
}
}
return $this->dataStr;
}
//----------------------------------------------------------------------
public static function splitStringToQRinput($string, QRinput $input, $modeHint, $casesensitive = true)
{
if(is_null($string) || $string == '\0' || $string == '') {
throw new Exception('empty string!!!');
}
$split = new QRsplit($string, $input, $modeHint);
if(!$casesensitive)
$split->toUpper();
return $split->splitString();
}
}
/* End of file */
/* Location: ./application/libraries/ */

@ -0,0 +1,153 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class QRtools {
protected $ci;
public function __construct()
{
$this->ci =& get_instance();
}
//----------------------------------------------------------------------
public static function binarize($frame)
{
$len = count($frame);
foreach ($frame as &$frameLine) {
for($i=0; $i<$len; $i++) {
$frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0';
}
}
return $frame;
}
//----------------------------------------------------------------------
public static function tcpdfBarcodeArray($code, $mode = 'QR,L', $tcPdfVersion = '4.5.037')
{
$barcode_array = array();
if (!is_array($mode))
$mode = explode(',', $mode);
$eccLevel = 'L';
if (count($mode) > 1) {
$eccLevel = $mode[1];
}
$qrTab = QRcode::text($code, false, $eccLevel);
$size = count($qrTab);
$barcode_array['num_rows'] = $size;
$barcode_array['num_cols'] = $size;
$barcode_array['bcode'] = array();
foreach ($qrTab as $line) {
$arrAdd = array();
foreach(str_split($line) as $char)
$arrAdd[] = ($char=='1')?1:0;
$barcode_array['bcode'][] = $arrAdd;
}
return $barcode_array;
}
//----------------------------------------------------------------------
public static function clearCache()
{
self::$frames = array();
}
//----------------------------------------------------------------------
public static function buildCache()
{
QRtools::markTime('before_build_cache');
$mask = new QRmask();
for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) {
$frame = QRspec::newFrame($a);
if (QR_IMAGE) {
$fileName = QR_CACHE_DIR.'frame_'.$a.'.png';
QRimage::png(self::binarize($frame), $fileName, 1, 0);
}
$width = count($frame);
$bitMask = array_fill(0, $width, array_fill(0, $width, 0));
for ($maskNo=0; $maskNo<8; $maskNo++)
$mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true);
}
QRtools::markTime('after_build_cache');
}
//----------------------------------------------------------------------
public static function log($outfile, $err)
{
if (QR_LOG_DIR !== false) {
if ($err != '') {
if ($outfile !== false) {
file_put_contents(QR_LOG_DIR.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
} else {
file_put_contents(QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND);
}
}
}
}
//----------------------------------------------------------------------
public static function dumpMask($frame)
{
$width = count($frame);
for($y=0;$y<$width;$y++) {
for($x=0;$x<$width;$x++) {
echo ord($frame[$y][$x]).',';
}
}
}
//----------------------------------------------------------------------
public static function markTime($markerId)
{
list($usec, $sec) = explode(" ", microtime());
$time = ((float)$usec + (float)$sec);
if (!isset($GLOBALS['qr_time_bench']))
$GLOBALS['qr_time_bench'] = array();
$GLOBALS['qr_time_bench'][$markerId] = $time;
}
//----------------------------------------------------------------------
public static function timeBenchmark()
{
self::markTime('finish');
$lastTime = 0;
$startTime = 0;
$p = 0;
echo '<table cellpadding="3" cellspacing="1">
<thead><tr style="border-bottom:1px solid silver"><td colspan="2" style="text-align:center">BENCHMARK</td></tr></thead>
<tbody>';
foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) {
if ($p > 0) {
echo '<tr><th style="text-align:right">till '.$markerId.': </th><td>'.number_format($thisTime-$lastTime, 6).'s</td></tr>';
} else {
$startTime = $thisTime;
}
$p++;
$lastTime = $thisTime;
}
echo '</tbody><tfoot>
<tr style="border-top:2px solid black"><th style="text-align:right">TOTAL: </th><td>'.number_format($lastTime-$startTime, 6).'s</td></tr>
</tfoot>
</table>';
}
}

@ -0,0 +1,101 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>微信支付样例-退款</title>
</head>
<?php
/**
*
* example目录下为简单的支付样例仅能用于搭建快速体验微信支付使用
* 样例的作用仅限于指导如何使用sdk在安全上面仅做了简单处理 复制使用样例代码时请慎重
* 请勿直接直接使用样例对外提供服务
*
**/
require_once "../lib/WxPay.Api.php";
require_once 'log.php';
require_once "WxPay.Config.php";
if((isset($_REQUEST["transaction_id"]) && $_REQUEST["transaction_id"] != ""
&& !preg_match("/^[0-9a-zA-Z]{10,64}$/i", $_REQUEST["transaction_id"], $matches))
|| (isset($_REQUEST["out_trade_no"]) && $_REQUEST["out_trade_no"]!=""
&& !preg_match("/^[0-9a-zA-Z]{10,64}$/i", $_REQUEST["out_trade_no"], $matches))
|| (isset($_REQUEST["total_fee"]) && $_REQUEST["total_fee"] != ""
&& !preg_match("/^[0-9]{0,10}$/i", $_REQUEST["total_fee"], $matches))
|| (isset($_REQUEST["refund_fee"]) && $_REQUEST["refund_fee"] != ""
&& !preg_match("/^[0-9]{0,10}$/i", $_REQUEST["refund_fee"], $matches)))
{
header('HTTP/1.1 404 Not Found');
exit();
}
//初始化日志
$logHandler= new CLogFileHandler("../logs/".date('Y-m-d').'.log');
$log = Log::Init($logHandler, 15);
function printf_info($data)
{
foreach($data as $key=>$value){
echo "<font color='#f00;'>$key</font> : ".htmlspecialchars($value, ENT_QUOTES)." <br/>";
}
}
if(isset($_REQUEST["transaction_id"]) && $_REQUEST["transaction_id"] != ""){
try{
$transaction_id = $_REQUEST["transaction_id"];
$total_fee = $_REQUEST["total_fee"];
$refund_fee = $_REQUEST["refund_fee"];
$input = new WxPayRefund();
$input->SetTransaction_id($transaction_id);
$input->SetTotal_fee($total_fee);
$input->SetRefund_fee($refund_fee);
$config = new WxPayConfig();
$input->SetOut_refund_no("sdkphp".date("YmdHis"));
$input->SetOp_user_id($config->GetMerchantId());
printf_info(WxPayApi::refund($config, $input));
} catch(Exception $e) {
Log::ERROR(json_encode($e));
}
exit();
}
//$_REQUEST["out_trade_no"]= "122531270220150304194108";
///$_REQUEST["total_fee"]= "1";
//$_REQUEST["refund_fee"] = "1";
if(isset($_REQUEST["out_trade_no"]) && $_REQUEST["out_trade_no"] != ""){
try{
$out_trade_no = $_REQUEST["out_trade_no"];
$total_fee = $_REQUEST["total_fee"];
$refund_fee = $_REQUEST["refund_fee"];
$input = new WxPayRefund();
$input->SetOut_trade_no($out_trade_no);
$input->SetTotal_fee($total_fee);
$input->SetRefund_fee($refund_fee);
$config = new WxPayConfig();
$input->SetOut_refund_no("sdkphp".date("YmdHis"));
$input->SetOp_user_id($config->GetMerchantId());
printf_info(WxPayApi::refund($config, $input));
} catch(Exception $e) {
Log::ERROR(json_encode($e));
}
exit();
}
?>
<body>
<form action="#" method="post">
<div style="margin-left:2%;color:#f00">微信订单号和商户订单号选少填一个,微信订单号优先:</div><br/>
<div style="margin-left:2%;">微信订单号:</div><br/>
<input type="text" style="width:96%;height:35px;margin-left:2%;" name="transaction_id" /><br /><br />
<div style="margin-left:2%;">商户订单号:</div><br/>
<input type="text" style="width:96%;height:35px;margin-left:2%;" name="out_trade_no" /><br /><br />
<div style="margin-left:2%;">订单总金额(分)</div><br/>
<input type="text" style="width:96%;height:35px;margin-left:2%;" name="total_fee" /><br /><br />
<div style="margin-left:2%;">退款金额(分)</div><br/>
<input type="text" style="width:96%;height:35px;margin-left:2%;" name="refund_fee" /><br /><br />
<div align="center">
<input type="submit" value="提交退款" style="width:210px; height:50px; border-radius: 15px;background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer; color:white; font-size:16px;" type="button" onclick="callpay()" />
</div>
</form>
</body>
</html>

@ -0,0 +1,112 @@
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>微信支付样例-查退款单</title>
</head>
<?php
/**
*
* example目录下为简单的支付样例仅能用于搭建快速体验微信支付使用
* 样例的作用仅限于指导如何使用sdk在安全上面仅做了简单处理 复制使用样例代码时请慎重
* 请勿直接直接使用样例对外提供服务
*
**/
require_once "../lib/WxPay.Api.php";
require_once 'log.php';
require_once "WxPay.Config.php";
//初始化日志
$logHandler= new CLogFileHandler("../logs/".date('Y-m-d').'.log');
$log = Log::Init($logHandler, 15);
$matches = array();
if( (isset($_REQUEST["transaction_id"]) && $_REQUEST["transaction_id"] != ""
&& !preg_match("/^[0-9a-zA-Z]{10,64}$/i", $_REQUEST["transaction_id"], $matches))
|| (isset($_REQUEST["out_trade_no"]) && $_REQUEST["out_trade_no"] != ""
&& !preg_match("/^[0-9a-zA-Z]{10,64}$/i", $_REQUEST["out_trade_no"], $matches))
|| (isset($_REQUEST["out_refund_no"]) && $_REQUEST["out_refund_no"] != ""
&& !preg_match("/^[0-9a-zA-Z]{10,64}$/i", $_REQUEST["out_refund_no"], $matches))
|| (isset($_REQUEST["refund_id"]) && $_REQUEST["refund_id"] != ""
&& !preg_match("/^[0-9a-zA-Z]{10,64}$/i", $_REQUEST["refund_id"], $matches)))
{
header('HTTP/1.1 404 Not Found');
exit();
}
function printf_info($data)
{
foreach($data as $key=>$value){
echo "<font color='#f00;'>$key</font> : ".htmlspecialchars($value, ENT_QUOTES)." <br/>";
}
}
if(isset($_REQUEST["transaction_id"]) && $_REQUEST["transaction_id"] != ""){
try{
$transaction_id = $_REQUEST["transaction_id"];
$input = new WxPayRefundQuery();
$input->SetTransaction_id($transaction_id);
$config = new WxPayConfig();
printf_info(WxPayApi::refundQuery($config, $input));
} catch(Exception $e) {
Log::ERROR(json_encode($e));
}
}
if(isset($_REQUEST["out_trade_no"]) && $_REQUEST["out_trade_no"] != ""){
try{
$out_trade_no = $_REQUEST["out_trade_no"];
$input = new WxPayRefundQuery();
$input->SetOut_trade_no($out_trade_no);
$config = new WxPayConfig();
printf_info(WxPayApi::refundQuery($input));
} catch(Exception $e) {
Log::ERROR(json_encode($e));
}
exit();
}
if(isset($_REQUEST["out_refund_no"]) && $_REQUEST["out_refund_no"] != ""){
try{
$out_refund_no = $_REQUEST["out_refund_no"];
$input = new WxPayRefundQuery();
$input->SetOut_refund_no($out_refund_no);
$config = new WxPayConfig();
printf_info(WxPayApi::refundQuery($config, $input));
} catch(Exception $e) {
Log::ERROR(json_encode($e));
}
exit();
}
if(isset($_REQUEST["refund_id"]) && $_REQUEST["refund_id"] != ""){
try{
$refund_id = $_REQUEST["refund_id"];
$input = new WxPayRefundQuery();
$input->SetRefund_id($refund_id);
$config = new WxPayConfig();
printf_info(WxPayApi::refundQuery($config, $input));
} catch(Exception $e) {
Log::ERROR(json_encode($e));
}
exit();
}
?>
<body>
<form action="#" method="post">
<div style="margin-left:2%;color:#f00">微信订单号、商户订单号、微信订单号、微信退款单号选填至少一个,微信退款单号优先:</div><br/>
<div style="margin-left:2%;">微信订单号:</div><br/>
<input type="text" style="width:96%;height:35px;margin-left:2%;" name="transaction_id" /><br /><br />
<div style="margin-left:2%;">商户订单号:</div><br/>
<input type="text" style="width:96%;height:35px;margin-left:2%;" name="out_trade_no" /><br /><br />
<div style="margin-left:2%;">商户退款单号:</div><br/>
<input type="text" style="width:96%;height:35px;margin-left:2%;" name="out_refund_no" /><br /><br />
<div style="margin-left:2%;">微信退款单号:</div><br/>
<input type="text" style="width:96%;height:35px;margin-left:2%;" name="refund_id" /><br /><br />
<div align="center">
<input type="submit" value="查询" style="width:210px; height:50px; border-radius: 15px;background-color:#FE6714; border:0px #FE6714 solid; cursor: pointer; color:white; font-size:16px;" type="button" onclick="callpay()" />
</div>
</form>
</body>
</html>

@ -0,0 +1,46 @@
<?php
require_once "lib/WxPay.Api.php";
require_once "WxPay.NativePay.php";
defined('BASEPATH') OR exit('No direct script access allowed');
class Wxpay_native
{
protected $ci;
public function __construct()
{
$this->ci =& get_instance();
}
//模式二
/**
* 流程:
* 1、调用统一下单取得code_url生成二维码
* 2、用户扫描二维码进行支付
* 3、支付完成之后微信服务器会通知支付成功
* 4、在支付成功通知中需要查单确认是否真正支付成功notify.php
*/
public function qrcode_url()
{
$input = new WxPayUnifiedOrder();
$input->SetBody("test");
$input->SetAttach("test");
$input->SetOut_trade_no("sdkphp123456789".date("YmdHis"));
$input->SetTotal_fee("1");
$input->SetTime_start(date("YmdHis"));
$input->SetTime_expire(date("YmdHis", time() + 600));
$input->SetGoods_tag("test");
$input->SetNotify_url("http://paysdk.weixin.qq.com/notify.php");
$input->SetTrade_type("NATIVE");
$input->SetProduct_id("123456789");
$result = $notify->GetPayUrl($input);
$url2 = $result["code_url"];
}
}
/* End of file Wxpay_native.php */
/* Location: ./CHT/third_party/pay/libraries/wxpay/Wxpay_native.php */

@ -0,0 +1,281 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Order_model extends CI_Model {
public function __construct()
{
parent::__construct();
$this->ht = $this->load->database('HT', TRUE);
}
public function get_order_contact($coli_sn, $order_type='227002')
{
$sql = "SELECT GUT_FirstName+' '+GUT_LastName fullname
,GUT_Email email
,case ISNULL(GUT_MoveTel,'') when '' then GUT_TEL else GUT_MoveTel end phone
,g.GUT_POST nation
from BIZ_GUEST g
INNER JOIN BIZ_ConfirmLineInfo coli on coli.COLI_GUT_SN=g.GUT_SN
WHERE COLI_SN=?";
if ($order_type !== '227002' && $order_type !== null) {
$sql = "SELECT top 1
case isnull(CUL_IsLinkMan,0) when 1 then MEI_Phone else '' end as phone
,(select COI_CountryCode from COuntryInfo
where COI_SN=MEI_Country
) as nation
,MEI_MailList email
,(isnull(MEI_LastName,'') +' '+ isnull(MEI_FirstName,'')) as fullname
from CustomerList cul
inner join MemberInfo mei on MEI_SN=CUL_CUI_SN
where 1=1
and cul.DeleteFlag=0 and mei.DeleteFlag=0
and CUL_COLI_SN = ?
order by cul.CUL_IsLinkMan desc ";
}
$contact_row = $this->ht->query($sql, array($coli_sn))->row_array();
if ( ! empty($contact_row)) {
$contact_row['phone_no'] = $contact_row['phone'];
if (false !== strripos($contact_row['phone'], ":")) {
$contact_row['phone_no'] = substr($contact_row['phone_no'], strripos($contact_row['phone_no'], ":")+1);
}
$contact_row['phone_no'] = $this->real_phone_number($contact_row['phone_no'],$contact_row['nation']);
}
return $contact_row;
}
public function real_phone_number($phone, $nation_code)
{
$nation_str = "+" . $nation_code;
$cut_nation = str_replace($nation_str, "", $phone);
return mb_ereg_replace('[\D]', '', $cut_nation);
}
public function orders($wu_id)
{
$sql = "SELECT orders.*
,PAG.PAG2_Name tourName,pag.PAG2_Attraction tourAttraction
,CONVERT(date, COLD_StartDate) startDate
--test:先设置一个字段.todo:是否完成电子反馈表
,case when COLD_StartDate>'2019-06-01' then 0 else 1 end evaluationDone
,isnull((select top 1 'Paid ' from Tourmanager.dbo.BIZ_GroupAccountInfo a where a.DeleteFlag=0 and GAI_COLI_SN=orders.coli),'Unpaid')
as ispaid
from (
select
COLI_GroupCode groupCode,COLI_GRI_SN groupId,COLI_ID orderId, COLI_SN coli
,(select top 1 COLD_SN from BIZ_ConfirmLineDetail where deleteflag=0 and cold_coli_sn=coli_sn order by cold_startdate
) as COLD_SN0
,COLI_IsSuccess isSuccess
,COLI_ApplyDate orderDate
from BIZ_ConfirmLineInfo coli
where 1=1
and exists(
select 1 from InfoManager.dbo.wx_customer where WC_WU_id=? and WC_COLI_SN=coli.COLI_SN
)
) as orders
inner join BIZ_ConfirmLineDetail cold on cold.COLD_SN=orders.COLD_SN0
inner join BIZ_PackageInfo2 pag on pag.PAG2_PAG_SN=cold.COLD_ServiceSN and pag.PAG2_LGC=1
order by
--evaluationDone asc,
-- startDate asc
orders.orderDate desc
";
return $this->ht->query($sql, array($wu_id))->result_array();
}
public function get_pag_tour_info($external_id)
{
$sql = "SELECT top 1 p.*
,(select top 1 SYC_SN from V_System_Code where SYC2_CodeDiscribe=sc.SYC2_CodeDiscribe and SYC_Type=32 and DeleteFlag=0 and LGC_LGC=2 ) as sourcetype32
from BIZ_PackageInfo p
left join V_System_Code sc on SYC_SN = PAG_sourceType and SYC_Type=132 AND LGC_LGC=2
where isnull(p.DeleteFlag,0)=0
and charindex(?,p.PAG_WebBR)>0";
return $this->ht->query($sql, array(",$external_id,"))->row_array();
}
public function biz_make_order_number() {
include('c:/database_conn.php');
$connection = array(
'UID' => $db['HT']['username'],
'PWD' => $db['HT']['password'],
'Database' => 'tourmanager',
'ConnectionPooling' => 1,
'CharacterSet' => 'utf-8',
'ReturnDatesAsStrings' => 1
);
$conn = sqlsrv_connect($db['HT']['hostname'], $connection);
$stmt = sqlsrv_query($conn, "DECLARE @COLI_ID varchar(40); EXEC dbo.SP_GetBIZOrderNo @COLI_ID OUT; select @COLI_ID coli_id;");
if ($stmt === false) {
echo "Error in executing statement 3.\n";
die(print_r(sqlsrv_errors(), true));
} else {
//存储过程中每一个select都会产生一个结果集取某个结果集就需要从第一个移动到需要的那个结果集
//如果结果集为空就移到下一个
while (sqlsrv_has_rows($stmt) !== TRUE) {
sqlsrv_next_result($stmt);
}
$result_object = array();
while ($row = sqlsrv_fetch_object($stmt)) {
$result_object[] = $row;
}
sqlsrv_free_stmt($stmt);
sqlsrv_close($conn);
return $result_object[0];
}
}
public function order_save($coli_arr=array())
{
$this->ht->insert('BIZ_ConfirmLineInfo', $coli_arr);
return $this->ht->insert_id();
}
public function book_detail_save($cold_arr=array())
{
$this->ht->insert('BIZ_ConfirmLineDetail', $cold_arr);
return $this->ht->insert_id();
}
public function guest_save($guest=array())
{
$this->ht->insert('BIZ_guest', $guest);
return $this->ht->insert_id();
// return $this->ht->query('SELECT top 1 GUT_SN from BIZ_GUEST where GUT_Email=? order by GUT_SN desc', array($guest['GUT_Email']))->row()->GUT_SN;
}
public function book_people_save($book_people=array())
{
$this->ht->insert('BIZ_BookPeople', $book_people);
return $this->ht->insert_id();
// return $this->ht->query('SELECT top 1 BPE_SN from BIZ_BookPeople where BPE_Passport=? order by BPE_SN desc', array($book_people['BPE_Passport']))->row()->BPE_SN;
}
public function biz_bookpeople_List_save($arr=array())
{
$this->ht->insert('BIZ_BookPeopleList', $arr);
return $this->ht->insert_id();
}
public function pag_order_save($poi_arr=array())
{
$this->ht->insert('BIZ_PackageOrderInfo', $poi_arr);
return $this->ht->insert_id();
}
public function order_info_to_pay($coli_sn, $pending=null)
{
$column = ""; $calc = "";
if ($pending===null) {
$column = " COLI_Price price, ";
$calc = " (select Tourmanager.dbo.ConvertToRMB(coli.COLI_Currency, coli.COLI_Price)) as cny_price ";
} else {
$column = " $pending as 'price', ";
$calc = " (select Tourmanager.dbo.ConvertToRMB(coli.COLI_Currency, $pending)) as cny_price ";
}
$sql = "SELECT
u.WU_userOpenId openid,COLI_ID,
$column
$calc
from InfoManager.dbo.wx_customer
inner join InfoManager.dbo.wx_user u on WU_id=WC_WU_id
inner join Tourmanager.dbo.BIZ_ConfirmLineInfo coli on COLI_SN=WC_COLI_SN
where WC_COLI_SN=? ";
return $this->ht->query($sql, array($coli_sn))->row_array();
}
public function order_detail($coli_sn, $coli_id = null)
{
$ret = array();
bcscale(2);
/**
* booking tour detail
*/
// 支付结果使用ID, 不再获取SN
$id_sql = ($coli_sn===0&&$coli_id!==null) ? "COLI_ID='$coli_id'" : "COLI_SN=$coli_sn";
$sql = "SELECT
c.COLI_SN coli,c.COLI_ID orderId,c.COLI_State orderStep,c.COLI_OPI_ID opi,
convert(date,COLD_StartDate) startDate,
isnull((select top 1 1 from Tourmanager.dbo.BIZ_GroupAccountInfo a where a.DeleteFlag=0 and GAI_COLI_SN=c.COLI_SN),0)
as ispaid,
convert(decimal(11,2),c.COLI_Price) totalPrice,c.COLI_Currency currency,
c.COLI_GroupCode groupCode,p.PAG2_PAG_SN as tourId
,convert(varchar(10),d.COLD_personNum) + ' Adults; ' +
case when d.COLD_childNum>0 then convert(varchar(10), d.COLD_childNum)+' Children; '
else '' end
as personNum
,(select top 1 g.GUT_FirstName from BIZ_Guest g where GUT_SN=COLI_GUT_SN) as leader
,po.POI_hotel as hotelName
,po.POI_hotelAddress as hotelAddress
,po.POI_hotelPhone as hotelTel
,p.PAG2_Attraction as attraction,PAG2_Title as schedule,p.PAG2_Name as tourName
,isnull(ps.PAGS_describ, '') as subTourInfo
from Tourmanager.dbo.BIZ_ConfirmLineInfo c
inner join Tourmanager.dbo.BIZ_ConfirmLineDetail d on c.COLI_SN=d.COLD_COLI_SN
and d.DeleteFlag=0
left join biz_packageOrderinfo po on po.POI_COLD_SN=d.COLD_SN
left join Tourmanager.dbo.BIZ_PackageInfo2 p on p.PAG2_PAG_SN=d.COLD_ServiceSN and p.PAG2_LGC=1
left join Tourmanager.dbo.BIZ_PackageInfoSub ps on ps.PAGS_SN=d.COLD_ServiceSN2 and ps.PAGS_LGC=1
where $id_sql
order by d.COLD_StartDate asc";
$ret['orderTour'] = $this->ht->query($sql)->result_array();
$sqlb = "SELECT
a.GAI_SQJE paidValue,a.GAI_SQJECurrency paidCurrency
,case when a.gai_sqje>0 then 'pay' else 'refund' end as fundAction
from Tourmanager.dbo.BIZ_GroupAccountInfo a
where a.GAI_COLI_SN=?
and a.DeleteFlag=0
order by a.GAI_SQDate asc";
$ret['paymentList'] = $this->ht->query($sqlb, array($coli_sn))->result_array();
$sqlp = "SELECT
CONVERT(decimal(10,2),isnull(sum(paid.paidQuote),0)) as paidQuote
from (
select
isnull(a.GAI_SQJE,0) paidValue,isnull(a.GAI_SQJECurrency,'USD') paidCurrency
,Tourmanager.dbo.ConvertCurrencyToCurrency(1, isnull(a.GAI_SQJECurrency,'USD'), 'USD', isnull(a.GAI_SQJE,0)) as paidQuote
,case when a.gai_sqje>0 then 'pay' else 'refund' end as fundAction
from Tourmanager.dbo.BIZ_GroupAccountInfo a
where a.GAI_COLI_SN=?
and a.DeleteFlag=0
) paid";
$ret['paidQuote'] = $this->ht->query($sqlp, array($coli_sn))->row()->paidQuote;
$ret['paidQuote'] = number_format($ret['paidQuote'], 2, '.', '');
$ret['pendingBalance'] = bcsub($ret['orderTour'][0]['totalPrice'], $ret['paidQuote']);
// $ret['pendingBalance'] = bcsub(1, 0); // test: $ret['paidQuote']
$ret['pendingBalance'] = $ret['pendingBalance']>0 ? $ret['pendingBalance'] : 0;
if (null !== $ret['orderTour'][0]['opi']) {
$operator_sql = "SELECT opi.OPI_SN id,opi.OPI_Name chineseName,opi.OPI_FirstName englishName2,OPI_MoveTelephone tel,OPI_Email email,opi2.OPI2_Name englishName
from OperatorInfo opi
left join OperatorInfo2 opi2 on opi2.OPI2_OPI_SN=OPI_SN and opi2.OPI2_LGC=1
where OPI_SN=" . $ret['orderTour'][0]['opi'] . " AND OPI_SN<>435";
$ret['operator'] = $this->ht->query($operator_sql)->row();
}
return $ret;
}
/*
* 发送邮件
*/
function SendMail($fromName, $fromEmail, $toName, $toEmail, $subject, $body) {
$sql = "INSERT INTO tourmanager.dbo.Email_AutomaticSend \n"
. " ( \n"
. " M_ReplyToName, M_ReplyToEmail, M_ToName, M_ToEmail, M_Title, M_Body, M_Web, \n"
. " M_FromName, M_State,M_AddTime \n"
. " ) \n"
. "VALUES \n"
. " ( \n"
. " ?, ?, ?, ?, ?, N?, ?, ?, 0, GETDATE() \n"
. " ) ";
$query = $this->ht->query($sql,
array(substr($fromName, 0, 127), $fromEmail, substr($toName, 0, 127), $toEmail, $subject, $body, 'wechat-notify', 'Auto mail')
);
return $query;
}
}
/* End of file Order_model.php */

@ -0,0 +1,119 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Wechat_service_model extends CI_Model {
public function __construct()
{
parent::__construct();
$this->info = $this->load->database('INFO', TRUE);
}
public function insert_wechat_notify($arr)
{
$this->info->insert('wx_service_notify', $arr);
return $this->info->query("SELECT MAX(wn_id) wn_id from wx_service_notify")
->row()->wn_id;
}
public function if_user_exists($arr)
{
$sql = "SELECT 1 from wx_user where wu_useropenid=? ";
$if = $this->info->query($sql, $arr['wu_useropenid'])->num_rows();
return $if > 0;
}
public function update_wechat_user($arr)
{
$where = " wu_useropenid='" . $arr['wu_useropenid'] . "'";
return $this->info->update('wx_user', $arr, $where);
}
public function insert_wechat_user($arr)
{
if (true === $this->if_user_exists($arr)) {
$this->update_wechat_user($arr);
} else {
$this->info->insert('wx_user', $arr);
}
return $this->info->query("SELECT MAX(wu_id) wu_id from wx_user where wu_useropenid=?", array($arr['wu_useropenid']))
->row()->wu_id;
}
public function insert_captcha($arr)
{
$this->info->insert('Wx_CaptCha', $arr);
return $this->info->query("SELECT MAX(WCC_id) WCC_id from Wx_CaptCha")
->row()->wcc_id;
}
public function insert_wechat_customer($arr)
{
$this->info->insert('wx_customer', $arr);
return $this->info->query("SELECT MAX(wc_id) wc_id from wx_customer")
->row()->wc_id;
}
public function insert_wechat_push($arr)
{
$this->info->insert('wx_service_push', $arr);
return $this->info->query("SELECT MAX(wp_id) wp_id from wx_service_push")
->row()->wp_id;
}
public function set_captcha_pass($WCC_id)
{
$sql = "UPDATE wx_captcha
SET wcc_status=1, wcc_successtime=GETDATE()
WHERE wcc_id=? ";
return $this->info->query($sql, array($WCC_id));
}
public function get_user($user_id=null, $appid=null, $openid=null)
{
$param_arr = array();
$where_id = $user_id===null ? "" : " AND wu_id=? ";
$where_openid = ($openid===null) ? "" : " AND wu_hostappid=? and wu_useropenid=? ";
$sql = "SELECT * from wx_user
where 1=1 $where_id $where_openid ";
$where_id==="" ? $param_arr=array($appid, $openid) : null;
$where_openid==="" ? $param_arr=array($user_id) : null;
if ($where_id==='' && $where_openid==='') {
return array();
}
$user = $this->info->query($sql, $param_arr)->row_array();
return $user;
}
public function get_verify($WU_id, $captcha)
{
$sql = "SELECT top 1 *
,DATEADD(S, ISNULL(wcc_expireseconds, 300),wcc_createtime) expire_time
from wx_captcha
where wcc_wu_id=? and wcc_value=?
order by wcc_status asc,wcc_createtime desc";
$user_captcha = $this->info->query($sql, array($WU_id, $captcha))->row_array();
return $user_captcha;
}
public function if_order_bound($coli_sn, $order_type)
{
$sql = "SELECT 1 from wx_user
where wu_coli_sn = ?
and wu_htordertype=? ";
$ret = $this->info->query($sql, array($coli_sn, $order_type))->num_rows();
return $ret>0;
}
public function get_customer($coli_sn)
{
$sql = "SELECT top 1 * from wx_customer
where wc_coli_sn=?";
$ret = $this->info->query($sql, array($coli_sn))->row_array();
return $ret;
}
}
/* End of file Wechat_service_model.php */

@ -0,0 +1,10 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

@ -0,0 +1,10 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

@ -0,0 +1,10 @@
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

@ -0,0 +1,88 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Welcome to CodeIgniter</title>
<style type="text/css">
::selection{ background-color: #E13300; color: white; }
::moz-selection{ background-color: #E13300; color: white; }
::webkit-selection{ background-color: #E13300; color: white; }
body {
background-color: #fff;
margin: 40px;
font: 13px/20px normal Helvetica, Arial, sans-serif;
color: #4F5155;
}
a {
color: #003399;
background-color: transparent;
font-weight: normal;
}
h1 {
color: #444;
background-color: transparent;
border-bottom: 1px solid #D0D0D0;
font-size: 19px;
font-weight: normal;
margin: 0 0 14px 0;
padding: 14px 15px 10px 15px;
}
code {
font-family: Consolas, Monaco, Courier New, Courier, monospace;
font-size: 12px;
background-color: #f9f9f9;
border: 1px solid #D0D0D0;
color: #002166;
display: block;
margin: 14px 0 14px 0;
padding: 12px 10px 12px 10px;
}
#body{
margin: 0 15px 0 15px;
}
p.footer{
text-align: right;
font-size: 11px;
border-top: 1px solid #D0D0D0;
line-height: 32px;
padding: 0 10px 0 10px;
margin: 20px 0 0 0;
}
#container{
margin: 10px;
border: 1px solid #D0D0D0;
-webkit-box-shadow: 0 0 8px #D0D0D0;
}
</style>
</head>
<body>
<div id="container">
<h1>Welcome to CodeIgniter!</h1>
<div id="body">
<p>The page you are looking at is being generated dynamically by CodeIgniter.</p>
<p>If you would like to edit this page you'll find it located at:</p>
<code>application/views/welcome_message.php</code>
<p>The corresponding controller for this page is found at:</p>
<code>application/controllers/welcome.php</code>
<p>If you are exploring CodeIgniter for the very first time, you should start by reading the <a href="user_guide/">User Guide</a>.</p>
</div>
<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds</p>
</div>
</body>
</html>

@ -0,0 +1,315 @@
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014 - 2017, British Columbia Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
* @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
* @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 1.0.0
* @filesource
*/
/*
*---------------------------------------------------------------
* APPLICATION ENVIRONMENT
*---------------------------------------------------------------
*
* You can load different configurations depending on your
* current environment. Setting the environment also influences
* things like logging and error reporting.
*
* This can be set to anything, but default usage is:
*
* development
* testing
* production
*
* NOTE: If you change these, also change the error_reporting() code below
*/
define('ENVIRONMENT', 'development');
/*
*---------------------------------------------------------------
* ERROR REPORTING
*---------------------------------------------------------------
*
* Different environments will require different levels of error reporting.
* By default development will show errors but testing and live will hide them.
*/
switch (ENVIRONMENT)
{
case 'development':
error_reporting(-1);
ini_set('display_errors', 1);
break;
case 'testing':
case 'production':
ini_set('display_errors', 0);
if (version_compare(PHP_VERSION, '5.3', '>='))
{
error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
}
else
{
error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
}
break;
default:
header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
echo 'The application environment is not set correctly.';
exit(1); // EXIT_ERROR
}
/*
*---------------------------------------------------------------
* SYSTEM DIRECTORY NAME
*---------------------------------------------------------------
*
* This variable must contain the name of your "system" directory.
* Set the path if it is not in the same directory as this file.
*/
$system_path = 'system';
/*
*---------------------------------------------------------------
* APPLICATION DIRECTORY NAME
*---------------------------------------------------------------
*
* If you want this front controller to use a different "application"
* directory than the default one you can set its name here. The directory
* can also be renamed or relocated anywhere on your server. If you do,
* use an absolute (full) server path.
* For more info please see the user guide:
*
* https://codeigniter.com/user_guide/general/managing_apps.html
*
* NO TRAILING SLASH!
*/
$application_folder = 'application';
/*
*---------------------------------------------------------------
* VIEW DIRECTORY NAME
*---------------------------------------------------------------
*
* If you want to move the view directory out of the application
* directory, set the path to it here. The directory can be renamed
* and relocated anywhere on your server. If blank, it will default
* to the standard location inside your application directory.
* If you do move this, use an absolute (full) server path.
*
* NO TRAILING SLASH!
*/
$view_folder = '';
/*
* --------------------------------------------------------------------
* DEFAULT CONTROLLER
* --------------------------------------------------------------------
*
* Normally you will set your default controller in the routes.php file.
* You can, however, force a custom routing by hard-coding a
* specific controller class/function here. For most applications, you
* WILL NOT set your routing here, but it's an option for those
* special instances where you might want to override the standard
* routing in a specific front controller that shares a common CI installation.
*
* IMPORTANT: If you set the routing here, NO OTHER controller will be
* callable. In essence, this preference limits your application to ONE
* specific controller. Leave the function name blank if you need
* to call functions dynamically via the URI.
*
* Un-comment the $routing array below to use this feature
*/
// The directory name, relative to the "controllers" directory. Leave blank
// if your controller is not in a sub-directory within the "controllers" one
// $routing['directory'] = '';
// The controller class file name. Example: mycontroller
// $routing['controller'] = '';
// The controller function you wish to be called.
// $routing['function'] = '';
/*
* -------------------------------------------------------------------
* CUSTOM CONFIG VALUES
* -------------------------------------------------------------------
*
* The $assign_to_config array below will be passed dynamically to the
* config class when initialized. This allows you to set custom config
* items or override any default config values found in the config.php file.
* This can be handy as it permits you to share one application between
* multiple front controller files, with each file containing different
* config values.
*
* Un-comment the $assign_to_config array below to use this feature
*/
// $assign_to_config['name_of_config_item'] = 'value of config item';
// --------------------------------------------------------------------
// END OF USER CONFIGURABLE SETTINGS. DO NOT EDIT BELOW THIS LINE
// --------------------------------------------------------------------
/*
* ---------------------------------------------------------------
* Resolve the system path for increased reliability
* ---------------------------------------------------------------
*/
// Set the current directory correctly for CLI requests
if (defined('STDIN'))
{
chdir(dirname(__FILE__));
}
if (($_temp = realpath($system_path)) !== FALSE)
{
$system_path = $_temp.DIRECTORY_SEPARATOR;
}
else
{
// Ensure there's a trailing slash
$system_path = strtr(
rtrim($system_path, '/\\'),
'/\\',
DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
).DIRECTORY_SEPARATOR;
}
// Is the system path correct?
if ( ! is_dir($system_path))
{
header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
echo 'Your system folder path does not appear to be set correctly. Please open the following file and correct this: '.pathinfo(__FILE__, PATHINFO_BASENAME);
exit(3); // EXIT_CONFIG
}
/*
* -------------------------------------------------------------------
* Now that we know the path, set the main path constants
* -------------------------------------------------------------------
*/
// The name of THIS file
define('SELF', pathinfo(__FILE__, PATHINFO_BASENAME));
// Path to the system directory
define('BASEPATH', $system_path);
// Path to the front controller (this file) directory
define('FCPATH', dirname(__FILE__).DIRECTORY_SEPARATOR);
// Name of the "system" directory
define('SYSDIR', basename(BASEPATH));
// The path to the "application" directory
if (is_dir($application_folder))
{
if (($_temp = realpath($application_folder)) !== FALSE)
{
$application_folder = $_temp;
}
else
{
$application_folder = strtr(
rtrim($application_folder, '/\\'),
'/\\',
DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
);
}
}
elseif (is_dir(BASEPATH.$application_folder.DIRECTORY_SEPARATOR))
{
$application_folder = BASEPATH.strtr(
trim($application_folder, '/\\'),
'/\\',
DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
);
}
else
{
header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
echo 'Your application folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF;
exit(3); // EXIT_CONFIG
}
define('APPPATH', $application_folder.DIRECTORY_SEPARATOR);
// The path to the "views" directory
if ( ! isset($view_folder[0]) && is_dir(APPPATH.'views'.DIRECTORY_SEPARATOR))
{
$view_folder = APPPATH.'views';
}
elseif (is_dir($view_folder))
{
if (($_temp = realpath($view_folder)) !== FALSE)
{
$view_folder = $_temp;
}
else
{
$view_folder = strtr(
rtrim($view_folder, '/\\'),
'/\\',
DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
);
}
}
elseif (is_dir(APPPATH.$view_folder.DIRECTORY_SEPARATOR))
{
$view_folder = APPPATH.strtr(
trim($view_folder, '/\\'),
'/\\',
DIRECTORY_SEPARATOR.DIRECTORY_SEPARATOR
);
}
else
{
header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
echo 'Your view folder path does not appear to be set correctly. Please open the following file and correct this: '.SELF;
exit(3); // EXIT_CONFIG
}
define('VIEWPATH', $view_folder.DIRECTORY_SEPARATOR);
/*
* --------------------------------------------------------------------
* LOAD THE BOOTSTRAP FILE
* --------------------------------------------------------------------
*
* And away we go...
*/
require_once BASEPATH.'core/CodeIgniter.php';

@ -0,0 +1,6 @@
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>

@ -0,0 +1,133 @@
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014 - 2017, British Columbia Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
* @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
* @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 1.0.0
* @filesource
*/
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Benchmark Class
*
* This class enables you to mark points and calculate the time difference
* between them. Memory consumption can also be displayed.
*
* @package CodeIgniter
* @subpackage Libraries
* @category Libraries
* @author EllisLab Dev Team
* @link https://codeigniter.com/user_guide/libraries/benchmark.html
*/
class CI_Benchmark {
/**
* List of all benchmark markers
*
* @var array
*/
public $marker = array();
/**
* Set a benchmark marker
*
* Multiple calls to this function can be made so that several
* execution points can be timed.
*
* @param string $name Marker name
* @return void
*/
public function mark($name)
{
$this->marker[$name] = microtime(TRUE);
}
// --------------------------------------------------------------------
/**
* Elapsed time
*
* Calculates the time difference between two marked points.
*
* If the first parameter is empty this function instead returns the
* {elapsed_time} pseudo-variable. This permits the full system
* execution time to be shown in a template. The output class will
* swap the real value for this variable.
*
* @param string $point1 A particular marked point
* @param string $point2 A particular marked point
* @param int $decimals Number of decimal places
*
* @return string Calculated elapsed time on success,
* an '{elapsed_string}' if $point1 is empty
* or an empty string if $point1 is not found.
*/
public function elapsed_time($point1 = '', $point2 = '', $decimals = 4)
{
if ($point1 === '')
{
return '{elapsed_time}';
}
if ( ! isset($this->marker[$point1]))
{
return '';
}
if ( ! isset($this->marker[$point2]))
{
$this->marker[$point2] = microtime(TRUE);
}
return number_format($this->marker[$point2] - $this->marker[$point1], $decimals);
}
// --------------------------------------------------------------------
/**
* Memory Usage
*
* Simply returns the {memory_usage} marker.
*
* This permits it to be put it anywhere in a template
* without the memory being calculated until the end.
* The output class will swap the real value for this variable.
*
* @return string '{memory_usage}'
*/
public function memory_usage()
{
return '{memory_usage}';
}
}

@ -0,0 +1,559 @@
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014 - 2017, British Columbia Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
* @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
* @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 1.0.0
* @filesource
*/
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* System Initialization File
*
* Loads the base classes and executes the request.
*
* @package CodeIgniter
* @subpackage CodeIgniter
* @category Front-controller
* @author EllisLab Dev Team
* @link https://codeigniter.com/user_guide/
*/
/**
* CodeIgniter Version
*
* @var string
*
*/
const CI_VERSION = '3.1.5';
/*
* ------------------------------------------------------
* Load the framework constants
* ------------------------------------------------------
*/
if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/constants.php'))
{
require_once(APPPATH.'config/'.ENVIRONMENT.'/constants.php');
}
if (file_exists(APPPATH.'config/constants.php'))
{
require_once(APPPATH.'config/constants.php');
}
/*
* ------------------------------------------------------
* Load the global functions
* ------------------------------------------------------
*/
require_once(BASEPATH.'core/Common.php');
/*
* ------------------------------------------------------
* Security procedures
* ------------------------------------------------------
*/
if ( ! is_php('5.4'))
{
ini_set('magic_quotes_runtime', 0);
if ((bool) ini_get('register_globals'))
{
$_protected = array(
'_SERVER',
'_GET',
'_POST',
'_FILES',
'_REQUEST',
'_SESSION',
'_ENV',
'_COOKIE',
'GLOBALS',
'HTTP_RAW_POST_DATA',
'system_path',
'application_folder',
'view_folder',
'_protected',
'_registered'
);
$_registered = ini_get('variables_order');
foreach (array('E' => '_ENV', 'G' => '_GET', 'P' => '_POST', 'C' => '_COOKIE', 'S' => '_SERVER') as $key => $superglobal)
{
if (strpos($_registered, $key) === FALSE)
{
continue;
}
foreach (array_keys($$superglobal) as $var)
{
if (isset($GLOBALS[$var]) && ! in_array($var, $_protected, TRUE))
{
$GLOBALS[$var] = NULL;
}
}
}
}
}
/*
* ------------------------------------------------------
* Define a custom error handler so we can log PHP errors
* ------------------------------------------------------
*/
set_error_handler('_error_handler');
set_exception_handler('_exception_handler');
register_shutdown_function('_shutdown_handler');
/*
* ------------------------------------------------------
* Set the subclass_prefix
* ------------------------------------------------------
*
* Normally the "subclass_prefix" is set in the config file.
* The subclass prefix allows CI to know if a core class is
* being extended via a library in the local application
* "libraries" folder. Since CI allows config items to be
* overridden via data set in the main index.php file,
* before proceeding we need to know if a subclass_prefix
* override exists. If so, we will set this value now,
* before any classes are loaded
* Note: Since the config file data is cached it doesn't
* hurt to load it here.
*/
if ( ! empty($assign_to_config['subclass_prefix']))
{
get_config(array('subclass_prefix' => $assign_to_config['subclass_prefix']));
}
/*
* ------------------------------------------------------
* Should we use a Composer autoloader?
* ------------------------------------------------------
*/
if ($composer_autoload = config_item('composer_autoload'))
{
if ($composer_autoload === TRUE)
{
file_exists(APPPATH.'vendor/autoload.php')
? require_once(APPPATH.'vendor/autoload.php')
: log_message('error', '$config[\'composer_autoload\'] is set to TRUE but '.APPPATH.'vendor/autoload.php was not found.');
}
elseif (file_exists($composer_autoload))
{
require_once($composer_autoload);
}
else
{
log_message('error', 'Could not find the specified $config[\'composer_autoload\'] path: '.$composer_autoload);
}
}
/*
* ------------------------------------------------------
* Start the timer... tick tock tick tock...
* ------------------------------------------------------
*/
$BM =& load_class('Benchmark', 'core');
$BM->mark('total_execution_time_start');
$BM->mark('loading_time:_base_classes_start');
/*
* ------------------------------------------------------
* Instantiate the hooks class
* ------------------------------------------------------
*/
$EXT =& load_class('Hooks', 'core');
/*
* ------------------------------------------------------
* Is there a "pre_system" hook?
* ------------------------------------------------------
*/
$EXT->call_hook('pre_system');
/*
* ------------------------------------------------------
* Instantiate the config class
* ------------------------------------------------------
*
* Note: It is important that Config is loaded first as
* most other classes depend on it either directly or by
* depending on another class that uses it.
*
*/
$CFG =& load_class('Config', 'core');
// Do we have any manually set config items in the index.php file?
if (isset($assign_to_config) && is_array($assign_to_config))
{
foreach ($assign_to_config as $key => $value)
{
$CFG->set_item($key, $value);
}
}
/*
* ------------------------------------------------------
* Important charset-related stuff
* ------------------------------------------------------
*
* Configure mbstring and/or iconv if they are enabled
* and set MB_ENABLED and ICONV_ENABLED constants, so
* that we don't repeatedly do extension_loaded() or
* function_exists() calls.
*
* Note: UTF-8 class depends on this. It used to be done
* in it's constructor, but it's _not_ class-specific.
*
*/
$charset = strtoupper(config_item('charset'));
ini_set('default_charset', $charset);
if (extension_loaded('mbstring'))
{
define('MB_ENABLED', TRUE);
// mbstring.internal_encoding is deprecated starting with PHP 5.6
// and it's usage triggers E_DEPRECATED messages.
@ini_set('mbstring.internal_encoding', $charset);
// This is required for mb_convert_encoding() to strip invalid characters.
// That's utilized by CI_Utf8, but it's also done for consistency with iconv.
mb_substitute_character('none');
}
else
{
define('MB_ENABLED', FALSE);
}
// There's an ICONV_IMPL constant, but the PHP manual says that using
// iconv's predefined constants is "strongly discouraged".
if (extension_loaded('iconv'))
{
define('ICONV_ENABLED', TRUE);
// iconv.internal_encoding is deprecated starting with PHP 5.6
// and it's usage triggers E_DEPRECATED messages.
@ini_set('iconv.internal_encoding', $charset);
}
else
{
define('ICONV_ENABLED', FALSE);
}
if (is_php('5.6'))
{
ini_set('php.internal_encoding', $charset);
}
/*
* ------------------------------------------------------
* Load compatibility features
* ------------------------------------------------------
*/
require_once(BASEPATH.'core/compat/mbstring.php');
require_once(BASEPATH.'core/compat/hash.php');
require_once(BASEPATH.'core/compat/password.php');
require_once(BASEPATH.'core/compat/standard.php');
/*
* ------------------------------------------------------
* Instantiate the UTF-8 class
* ------------------------------------------------------
*/
$UNI =& load_class('Utf8', 'core');
/*
* ------------------------------------------------------
* Instantiate the URI class
* ------------------------------------------------------
*/
$URI =& load_class('URI', 'core');
/*
* ------------------------------------------------------
* Instantiate the routing class and set the routing
* ------------------------------------------------------
*/
$RTR =& load_class('Router', 'core', isset($routing) ? $routing : NULL);
/*
* ------------------------------------------------------
* Instantiate the output class
* ------------------------------------------------------
*/
$OUT =& load_class('Output', 'core');
/*
* ------------------------------------------------------
* Is there a valid cache file? If so, we're done...
* ------------------------------------------------------
*/
if ($EXT->call_hook('cache_override') === FALSE && $OUT->_display_cache($CFG, $URI) === TRUE)
{
exit;
}
/*
* -----------------------------------------------------
* Load the security class for xss and csrf support
* -----------------------------------------------------
*/
$SEC =& load_class('Security', 'core');
/*
* ------------------------------------------------------
* Load the Input class and sanitize globals
* ------------------------------------------------------
*/
$IN =& load_class('Input', 'core');
/*
* ------------------------------------------------------
* Load the Language class
* ------------------------------------------------------
*/
$LANG =& load_class('Lang', 'core');
/*
* ------------------------------------------------------
* Load the app controller and local controller
* ------------------------------------------------------
*
*/
// Load the base controller class
require_once BASEPATH.'core/Controller.php';
/**
* Reference to the CI_Controller method.
*
* Returns current CI instance object
*
* @return CI_Controller
*/
function &get_instance()
{
return CI_Controller::get_instance();
}
if (file_exists(APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php'))
{
require_once APPPATH.'core/'.$CFG->config['subclass_prefix'].'Controller.php';
}
// Set a mark point for benchmarking
$BM->mark('loading_time:_base_classes_end');
/*
* ------------------------------------------------------
* Sanity checks
* ------------------------------------------------------
*
* The Router class has already validated the request,
* leaving us with 3 options here:
*
* 1) an empty class name, if we reached the default
* controller, but it didn't exist;
* 2) a query string which doesn't go through a
* file_exists() check
* 3) a regular request for a non-existing page
*
* We handle all of these as a 404 error.
*
* Furthermore, none of the methods in the app controller
* or the loader class can be called via the URI, nor can
* controller methods that begin with an underscore.
*/
$e404 = FALSE;
$class = ucfirst($RTR->class);
$method = $RTR->method;
if (empty($class) OR ! file_exists(APPPATH.'controllers/'.$RTR->directory.$class.'.php'))
{
$e404 = TRUE;
}
else
{
require_once(APPPATH.'controllers/'.$RTR->directory.$class.'.php');
if ( ! class_exists($class, FALSE) OR $method[0] === '_' OR method_exists('CI_Controller', $method))
{
$e404 = TRUE;
}
elseif (method_exists($class, '_remap'))
{
$params = array($method, array_slice($URI->rsegments, 2));
$method = '_remap';
}
elseif ( ! method_exists($class, $method))
{
$e404 = TRUE;
}
/**
* DO NOT CHANGE THIS, NOTHING ELSE WORKS!
*
* - method_exists() returns true for non-public methods, which passes the previous elseif
* - is_callable() returns false for PHP 4-style constructors, even if there's a __construct()
* - method_exists($class, '__construct') won't work because CI_Controller::__construct() is inherited
* - People will only complain if this doesn't work, even though it is documented that it shouldn't.
*
* ReflectionMethod::isConstructor() is the ONLY reliable check,
* knowing which method will be executed as a constructor.
*/
elseif ( ! is_callable(array($class, $method)))
{
$reflection = new ReflectionMethod($class, $method);
if ( ! $reflection->isPublic() OR $reflection->isConstructor())
{
$e404 = TRUE;
}
}
}
if ($e404)
{
if ( ! empty($RTR->routes['404_override']))
{
if (sscanf($RTR->routes['404_override'], '%[^/]/%s', $error_class, $error_method) !== 2)
{
$error_method = 'index';
}
$error_class = ucfirst($error_class);
if ( ! class_exists($error_class, FALSE))
{
if (file_exists(APPPATH.'controllers/'.$RTR->directory.$error_class.'.php'))
{
require_once(APPPATH.'controllers/'.$RTR->directory.$error_class.'.php');
$e404 = ! class_exists($error_class, FALSE);
}
// Were we in a directory? If so, check for a global override
elseif ( ! empty($RTR->directory) && file_exists(APPPATH.'controllers/'.$error_class.'.php'))
{
require_once(APPPATH.'controllers/'.$error_class.'.php');
if (($e404 = ! class_exists($error_class, FALSE)) === FALSE)
{
$RTR->directory = '';
}
}
}
else
{
$e404 = FALSE;
}
}
// Did we reset the $e404 flag? If so, set the rsegments, starting from index 1
if ( ! $e404)
{
$class = $error_class;
$method = $error_method;
$URI->rsegments = array(
1 => $class,
2 => $method
);
}
else
{
show_404($RTR->directory.$class.'/'.$method);
}
}
if ($method !== '_remap')
{
$params = array_slice($URI->rsegments, 2);
}
/*
* ------------------------------------------------------
* Is there a "pre_controller" hook?
* ------------------------------------------------------
*/
$EXT->call_hook('pre_controller');
/*
* ------------------------------------------------------
* Instantiate the requested controller
* ------------------------------------------------------
*/
// Mark a start point so we can benchmark the controller
$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_start');
$CI = new $class();
/*
* ------------------------------------------------------
* Is there a "post_controller_constructor" hook?
* ------------------------------------------------------
*/
$EXT->call_hook('post_controller_constructor');
/*
* ------------------------------------------------------
* Call the requested method
* ------------------------------------------------------
*/
call_user_func_array(array(&$CI, $method), $params);
// Mark a benchmark end point
$BM->mark('controller_execution_time_( '.$class.' / '.$method.' )_end');
/*
* ------------------------------------------------------
* Is there a "post_controller" hook?
* ------------------------------------------------------
*/
$EXT->call_hook('post_controller');
/*
* ------------------------------------------------------
* Send the final rendered output to the browser
* ------------------------------------------------------
*/
if ($EXT->call_hook('display_override') === FALSE)
{
$OUT->_display();
}
/*
* ------------------------------------------------------
* Is there a "post_system" hook?
* ------------------------------------------------------
*/
$EXT->call_hook('post_system');

@ -0,0 +1,849 @@
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014 - 2017, British Columbia Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
* @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
* @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 1.0.0
* @filesource
*/
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Common Functions
*
* Loads the base classes and executes the request.
*
* @package CodeIgniter
* @subpackage CodeIgniter
* @category Common Functions
* @author EllisLab Dev Team
* @link https://codeigniter.com/user_guide/
*/
// ------------------------------------------------------------------------
if ( ! function_exists('is_php'))
{
/**
* Determines if the current version of PHP is equal to or greater than the supplied value
*
* @param string
* @return bool TRUE if the current version is $version or higher
*/
function is_php($version)
{
static $_is_php;
$version = (string) $version;
if ( ! isset($_is_php[$version]))
{
$_is_php[$version] = version_compare(PHP_VERSION, $version, '>=');
}
return $_is_php[$version];
}
}
// ------------------------------------------------------------------------
if ( ! function_exists('is_really_writable'))
{
/**
* Tests for file writability
*
* is_writable() returns TRUE on Windows servers when you really can't write to
* the file, based on the read-only attribute. is_writable() is also unreliable
* on Unix servers if safe_mode is on.
*
* @link https://bugs.php.net/bug.php?id=54709
* @param string
* @return bool
*/
function is_really_writable($file)
{
// If we're on a Unix server with safe_mode off we call is_writable
if (DIRECTORY_SEPARATOR === '/' && (is_php('5.4') OR ! ini_get('safe_mode')))
{
return is_writable($file);
}
/* For Windows servers and safe_mode "on" installations we'll actually
* write a file then read it. Bah...
*/
if (is_dir($file))
{
$file = rtrim($file, '/').'/'.md5(mt_rand());
if (($fp = @fopen($file, 'ab')) === FALSE)
{
return FALSE;
}
fclose($fp);
@chmod($file, 0777);
@unlink($file);
return TRUE;
}
elseif ( ! is_file($file) OR ($fp = @fopen($file, 'ab')) === FALSE)
{
return FALSE;
}
fclose($fp);
return TRUE;
}
}
// ------------------------------------------------------------------------
if ( ! function_exists('load_class'))
{
/**
* Class registry
*
* This function acts as a singleton. If the requested class does not
* exist it is instantiated and set to a static variable. If it has
* previously been instantiated the variable is returned.
*
* @param string the class name being requested
* @param string the directory where the class should be found
* @param mixed an optional argument to pass to the class constructor
* @return object
*/
function &load_class($class, $directory = 'libraries', $param = NULL)
{
static $_classes = array();
// Does the class exist? If so, we're done...
if (isset($_classes[$class]))
{
return $_classes[$class];
}
$name = FALSE;
// Look for the class first in the local application/libraries folder
// then in the native system/libraries folder
foreach (array(APPPATH, BASEPATH) as $path)
{
if (file_exists($path.$directory.'/'.$class.'.php'))
{
$name = 'CI_'.$class;
if (class_exists($name, FALSE) === FALSE)
{
require_once($path.$directory.'/'.$class.'.php');
}
break;
}
}
// Is the request a class extension? If so we load it too
if (file_exists(APPPATH.$directory.'/'.config_item('subclass_prefix').$class.'.php'))
{
$name = config_item('subclass_prefix').$class;
if (class_exists($name, FALSE) === FALSE)
{
require_once(APPPATH.$directory.'/'.$name.'.php');
}
}
// Did we find the class?
if ($name === FALSE)
{
// Note: We use exit() rather than show_error() in order to avoid a
// self-referencing loop with the Exceptions class
set_status_header(503);
echo 'Unable to locate the specified class: '.$class.'.php';
exit(5); // EXIT_UNK_CLASS
}
// Keep track of what we just loaded
is_loaded($class);
$_classes[$class] = isset($param)
? new $name($param)
: new $name();
return $_classes[$class];
}
}
// --------------------------------------------------------------------
if ( ! function_exists('is_loaded'))
{
/**
* Keeps track of which libraries have been loaded. This function is
* called by the load_class() function above
*
* @param string
* @return array
*/
function &is_loaded($class = '')
{
static $_is_loaded = array();
if ($class !== '')
{
$_is_loaded[strtolower($class)] = $class;
}
return $_is_loaded;
}
}
// ------------------------------------------------------------------------
if ( ! function_exists('get_config'))
{
/**
* Loads the main config.php file
*
* This function lets us grab the config file even if the Config class
* hasn't been instantiated yet
*
* @param array
* @return array
*/
function &get_config(Array $replace = array())
{
static $config;
if (empty($config))
{
$file_path = APPPATH.'config/config.php';
$found = FALSE;
if (file_exists($file_path))
{
$found = TRUE;
require($file_path);
}
// Is the config file in the environment folder?
if (file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php'))
{
require($file_path);
}
elseif ( ! $found)
{
set_status_header(503);
echo 'The configuration file does not exist.';
exit(3); // EXIT_CONFIG
}
// Does the $config array exist in the file?
if ( ! isset($config) OR ! is_array($config))
{
set_status_header(503);
echo 'Your config file does not appear to be formatted correctly.';
exit(3); // EXIT_CONFIG
}
}
// Are any values being dynamically added or replaced?
foreach ($replace as $key => $val)
{
$config[$key] = $val;
}
return $config;
}
}
// ------------------------------------------------------------------------
if ( ! function_exists('config_item'))
{
/**
* Returns the specified config item
*
* @param string
* @return mixed
*/
function config_item($item)
{
static $_config;
if (empty($_config))
{
// references cannot be directly assigned to static variables, so we use an array
$_config[0] =& get_config();
}
return isset($_config[0][$item]) ? $_config[0][$item] : NULL;
}
}
// ------------------------------------------------------------------------
if ( ! function_exists('get_mimes'))
{
/**
* Returns the MIME types array from config/mimes.php
*
* @return array
*/
function &get_mimes()
{
static $_mimes;
if (empty($_mimes))
{
$_mimes = file_exists(APPPATH.'config/mimes.php')
? include(APPPATH.'config/mimes.php')
: array();
if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'))
{
$_mimes = array_merge($_mimes, include(APPPATH.'config/'.ENVIRONMENT.'/mimes.php'));
}
}
return $_mimes;
}
}
// ------------------------------------------------------------------------
if ( ! function_exists('is_https'))
{
/**
* Is HTTPS?
*
* Determines if the application is accessed via an encrypted
* (HTTPS) connection.
*
* @return bool
*/
function is_https()
{
if ( ! empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off')
{
return TRUE;
}
elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) === 'https')
{
return TRUE;
}
elseif ( ! empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off')
{
return TRUE;
}
return FALSE;
}
}
// ------------------------------------------------------------------------
if ( ! function_exists('is_cli'))
{
/**
* Is CLI?
*
* Test to see if a request was made from the command line.
*
* @return bool
*/
function is_cli()
{
return (PHP_SAPI === 'cli' OR defined('STDIN'));
}
}
// ------------------------------------------------------------------------
if ( ! function_exists('show_error'))
{
/**
* Error Handler
*
* This function lets us invoke the exception class and
* display errors using the standard error template located
* in application/views/errors/error_general.php
* This function will send the error page directly to the
* browser and exit.
*
* @param string
* @param int
* @param string
* @return void
*/
function show_error($message, $status_code = 500, $heading = 'An Error Was Encountered')
{
$status_code = abs($status_code);
if ($status_code < 100)
{
$exit_status = $status_code + 9; // 9 is EXIT__AUTO_MIN
$status_code = 500;
}
else
{
$exit_status = 1; // EXIT_ERROR
}
$_error =& load_class('Exceptions', 'core');
echo $_error->show_error($heading, $message, 'error_general', $status_code);
exit($exit_status);
}
}
// ------------------------------------------------------------------------
if ( ! function_exists('show_404'))
{
/**
* 404 Page Handler
*
* This function is similar to the show_error() function above
* However, instead of the standard error template it displays
* 404 errors.
*
* @param string
* @param bool
* @return void
*/
function show_404($page = '', $log_error = TRUE)
{
$_error =& load_class('Exceptions', 'core');
$_error->show_404($page, $log_error);
exit(4); // EXIT_UNKNOWN_FILE
}
}
// ------------------------------------------------------------------------
if ( ! function_exists('log_message'))
{
/**
* Error Logging Interface
*
* We use this as a simple mechanism to access the logging
* class and send messages to be logged.
*
* @param string the error level: 'error', 'debug' or 'info'
* @param string the error message
* @return void
*/
function log_message($level, $message)
{
static $_log;
if ($_log === NULL)
{
// references cannot be directly assigned to static variables, so we use an array
$_log[0] =& load_class('Log', 'core');
}
$_log[0]->write_log($level, $message);
}
}
// ------------------------------------------------------------------------
if ( ! function_exists('set_status_header'))
{
/**
* Set HTTP Status Header
*
* @param int the status code
* @param string
* @return void
*/
function set_status_header($code = 200, $text = '')
{
if (is_cli())
{
return;
}
if (empty($code) OR ! is_numeric($code))
{
show_error('Status codes must be numeric', 500);
}
if (empty($text))
{
is_int($code) OR $code = (int) $code;
$stati = array(
100 => 'Continue',
101 => 'Switching Protocols',
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
204 => 'No Content',
205 => 'Reset Content',
206 => 'Partial Content',
300 => 'Multiple Choices',
301 => 'Moved Permanently',
302 => 'Found',
303 => 'See Other',
304 => 'Not Modified',
305 => 'Use Proxy',
307 => 'Temporary Redirect',
400 => 'Bad Request',
401 => 'Unauthorized',
402 => 'Payment Required',
403 => 'Forbidden',
404 => 'Not Found',
405 => 'Method Not Allowed',
406 => 'Not Acceptable',
407 => 'Proxy Authentication Required',
408 => 'Request Timeout',
409 => 'Conflict',
410 => 'Gone',
411 => 'Length Required',
412 => 'Precondition Failed',
413 => 'Request Entity Too Large',
414 => 'Request-URI Too Long',
415 => 'Unsupported Media Type',
416 => 'Requested Range Not Satisfiable',
417 => 'Expectation Failed',
422 => 'Unprocessable Entity',
426 => 'Upgrade Required',
428 => 'Precondition Required',
429 => 'Too Many Requests',
431 => 'Request Header Fields Too Large',
500 => 'Internal Server Error',
501 => 'Not Implemented',
502 => 'Bad Gateway',
503 => 'Service Unavailable',
504 => 'Gateway Timeout',
505 => 'HTTP Version Not Supported',
511 => 'Network Authentication Required',
);
if (isset($stati[$code]))
{
$text = $stati[$code];
}
else
{
show_error('No status text available. Please check your status code number or supply your own message text.', 500);
}
}
if (strpos(PHP_SAPI, 'cgi') === 0)
{
header('Status: '.$code.' '.$text, TRUE);
return;
}
$server_protocol = (isset($_SERVER['SERVER_PROTOCOL']) && in_array($_SERVER['SERVER_PROTOCOL'], array('HTTP/1.0', 'HTTP/1.1', 'HTTP/2'), TRUE))
? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.1';
header($server_protocol.' '.$code.' '.$text, TRUE, $code);
}
}
// --------------------------------------------------------------------
if ( ! function_exists('_error_handler'))
{
/**
* Error Handler
*
* This is the custom error handler that is declared at the (relative)
* top of CodeIgniter.php. The main reason we use this is to permit
* PHP errors to be logged in our own log files since the user may
* not have access to server logs. Since this function effectively
* intercepts PHP errors, however, we also need to display errors
* based on the current error_reporting level.
* We do that with the use of a PHP error template.
*
* @param int $severity
* @param string $message
* @param string $filepath
* @param int $line
* @return void
*/
function _error_handler($severity, $message, $filepath, $line)
{
$is_error = (((E_ERROR | E_PARSE | E_COMPILE_ERROR | E_CORE_ERROR | E_USER_ERROR) & $severity) === $severity);
// When an error occurred, set the status header to '500 Internal Server Error'
// to indicate to the client something went wrong.
// This can't be done within the $_error->show_php_error method because
// it is only called when the display_errors flag is set (which isn't usually
// the case in a production environment) or when errors are ignored because
// they are above the error_reporting threshold.
if ($is_error)
{
set_status_header(500);
}
// Should we ignore the error? We'll get the current error_reporting
// level and add its bits with the severity bits to find out.
if (($severity & error_reporting()) !== $severity)
{
return;
}
$_error =& load_class('Exceptions', 'core');
$_error->log_exception($severity, $message, $filepath, $line);
// Should we display the error?
if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors')))
{
$_error->show_php_error($severity, $message, $filepath, $line);
}
// If the error is fatal, the execution of the script should be stopped because
// errors can't be recovered from. Halting the script conforms with PHP's
// default error handling. See http://www.php.net/manual/en/errorfunc.constants.php
if ($is_error)
{
exit(1); // EXIT_ERROR
}
}
}
// ------------------------------------------------------------------------
if ( ! function_exists('_exception_handler'))
{
/**
* Exception Handler
*
* Sends uncaught exceptions to the logger and displays them
* only if display_errors is On so that they don't show up in
* production environments.
*
* @param Exception $exception
* @return void
*/
function _exception_handler($exception)
{
$_error =& load_class('Exceptions', 'core');
$_error->log_exception('error', 'Exception: '.$exception->getMessage(), $exception->getFile(), $exception->getLine());
is_cli() OR set_status_header(500);
// Should we display the error?
if (str_ireplace(array('off', 'none', 'no', 'false', 'null'), '', ini_get('display_errors')))
{
$_error->show_exception($exception);
}
exit(1); // EXIT_ERROR
}
}
// ------------------------------------------------------------------------
if ( ! function_exists('_shutdown_handler'))
{
/**
* Shutdown Handler
*
* This is the shutdown handler that is declared at the top
* of CodeIgniter.php. The main reason we use this is to simulate
* a complete custom exception handler.
*
* E_STRICT is purposively neglected because such events may have
* been caught. Duplication or none? None is preferred for now.
*
* @link http://insomanic.me.uk/post/229851073/php-trick-catching-fatal-errors-e-error-with-a
* @return void
*/
function _shutdown_handler()
{
$last_error = error_get_last();
if (isset($last_error) &&
($last_error['type'] & (E_ERROR | E_PARSE | E_CORE_ERROR | E_CORE_WARNING | E_COMPILE_ERROR | E_COMPILE_WARNING)))
{
_error_handler($last_error['type'], $last_error['message'], $last_error['file'], $last_error['line']);
}
}
}
// --------------------------------------------------------------------
if ( ! function_exists('remove_invisible_characters'))
{
/**
* Remove Invisible Characters
*
* This prevents sandwiching null characters
* between ascii characters, like Java\0script.
*
* @param string
* @param bool
* @return string
*/
function remove_invisible_characters($str, $url_encoded = TRUE)
{
$non_displayables = array();
// every control character except newline (dec 10),
// carriage return (dec 13) and horizontal tab (dec 09)
if ($url_encoded)
{
$non_displayables[] = '/%0[0-8bcef]/i'; // url encoded 00-08, 11, 12, 14, 15
$non_displayables[] = '/%1[0-9a-f]/i'; // url encoded 16-31
$non_displayables[] = '/%7f/i'; // url encoded 127
}
$non_displayables[] = '/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]+/S'; // 00-08, 11, 12, 14-31, 127
do
{
$str = preg_replace($non_displayables, '', $str, -1, $count);
}
while ($count);
return $str;
}
}
// ------------------------------------------------------------------------
if ( ! function_exists('html_escape'))
{
/**
* Returns HTML escaped variable.
*
* @param mixed $var The input string or array of strings to be escaped.
* @param bool $double_encode $double_encode set to FALSE prevents escaping twice.
* @return mixed The escaped string or array of strings as a result.
*/
function html_escape($var, $double_encode = TRUE)
{
if (empty($var))
{
return $var;
}
if (is_array($var))
{
foreach (array_keys($var) as $key)
{
$var[$key] = html_escape($var[$key], $double_encode);
}
return $var;
}
return htmlspecialchars($var, ENT_QUOTES, config_item('charset'), $double_encode);
}
}
// ------------------------------------------------------------------------
if ( ! function_exists('_stringify_attributes'))
{
/**
* Stringify attributes for use in HTML tags.
*
* Helper function used to convert a string, array, or object
* of attributes to a string.
*
* @param mixed string, array, object
* @param bool
* @return string
*/
function _stringify_attributes($attributes, $js = FALSE)
{
$atts = NULL;
if (empty($attributes))
{
return $atts;
}
if (is_string($attributes))
{
return ' '.$attributes;
}
$attributes = (array) $attributes;
foreach ($attributes as $key => $val)
{
$atts .= ($js) ? $key.'='.$val.',' : ' '.$key.'="'.$val.'"';
}
return rtrim($atts, ',');
}
}
// ------------------------------------------------------------------------
if ( ! function_exists('function_usable'))
{
/**
* Function usable
*
* Executes a function_exists() check, and if the Suhosin PHP
* extension is loaded - checks whether the function that is
* checked might be disabled in there as well.
*
* This is useful as function_exists() will return FALSE for
* functions disabled via the *disable_functions* php.ini
* setting, but not for *suhosin.executor.func.blacklist* and
* *suhosin.executor.disable_eval*. These settings will just
* terminate script execution if a disabled function is executed.
*
* The above described behavior turned out to be a bug in Suhosin,
* but even though a fix was committed for 0.9.34 on 2012-02-12,
* that version is yet to be released. This function will therefore
* be just temporary, but would probably be kept for a few years.
*
* @link http://www.hardened-php.net/suhosin/
* @param string $function_name Function to check for
* @return bool TRUE if the function exists and is safe to call,
* FALSE otherwise.
*/
function function_usable($function_name)
{
static $_suhosin_func_blacklist;
if (function_exists($function_name))
{
if ( ! isset($_suhosin_func_blacklist))
{
$_suhosin_func_blacklist = extension_loaded('suhosin')
? explode(',', trim(ini_get('suhosin.executor.func.blacklist')))
: array();
}
return ! in_array($function_name, $_suhosin_func_blacklist, TRUE);
}
return FALSE;
}
}

@ -0,0 +1,379 @@
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014 - 2017, British Columbia Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
* @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
* @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 1.0.0
* @filesource
*/
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Config Class
*
* This class contains functions that enable config files to be managed
*
* @package CodeIgniter
* @subpackage Libraries
* @category Libraries
* @author EllisLab Dev Team
* @link https://codeigniter.com/user_guide/libraries/config.html
*/
class CI_Config {
/**
* List of all loaded config values
*
* @var array
*/
public $config = array();
/**
* List of all loaded config files
*
* @var array
*/
public $is_loaded = array();
/**
* List of paths to search when trying to load a config file.
*
* @used-by CI_Loader
* @var array
*/
public $_config_paths = array(APPPATH);
// --------------------------------------------------------------------
/**
* Class constructor
*
* Sets the $config data from the primary config.php file as a class variable.
*
* @return void
*/
public function __construct()
{
$this->config =& get_config();
// Set the base_url automatically if none was provided
if (empty($this->config['base_url']))
{
if (isset($_SERVER['SERVER_ADDR']))
{
if (strpos($_SERVER['SERVER_ADDR'], ':') !== FALSE)
{
$server_addr = '['.$_SERVER['SERVER_ADDR'].']';
}
else
{
$server_addr = $_SERVER['SERVER_ADDR'];
}
$base_url = (is_https() ? 'https' : 'http').'://'.$server_addr
.substr($_SERVER['SCRIPT_NAME'], 0, strpos($_SERVER['SCRIPT_NAME'], basename($_SERVER['SCRIPT_FILENAME'])));
}
else
{
$base_url = 'http://localhost/';
}
$this->set_item('base_url', $base_url);
}
log_message('info', 'Config Class Initialized');
}
// --------------------------------------------------------------------
/**
* Load Config File
*
* @param string $file Configuration file name
* @param bool $use_sections Whether configuration values should be loaded into their own section
* @param bool $fail_gracefully Whether to just return FALSE or display an error message
* @return bool TRUE if the file was loaded correctly or FALSE on failure
*/
public function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE)
{
$file = ($file === '') ? 'config' : str_replace('.php', '', $file);
$loaded = FALSE;
foreach ($this->_config_paths as $path)
{
foreach (array($file, ENVIRONMENT.DIRECTORY_SEPARATOR.$file) as $location)
{
$file_path = $path.'config/'.$location.'.php';
if (in_array($file_path, $this->is_loaded, TRUE))
{
return TRUE;
}
if ( ! file_exists($file_path))
{
continue;
}
include($file_path);
if ( ! isset($config) OR ! is_array($config))
{
if ($fail_gracefully === TRUE)
{
return FALSE;
}
show_error('Your '.$file_path.' file does not appear to contain a valid configuration array.');
}
if ($use_sections === TRUE)
{
$this->config[$file] = isset($this->config[$file])
? array_merge($this->config[$file], $config)
: $config;
}
else
{
$this->config = array_merge($this->config, $config);
}
$this->is_loaded[] = $file_path;
$config = NULL;
$loaded = TRUE;
log_message('debug', 'Config file loaded: '.$file_path);
}
}
if ($loaded === TRUE)
{
return TRUE;
}
elseif ($fail_gracefully === TRUE)
{
return FALSE;
}
show_error('The configuration file '.$file.'.php does not exist.');
}
// --------------------------------------------------------------------
/**
* Fetch a config file item
*
* @param string $item Config item name
* @param string $index Index name
* @return string|null The configuration item or NULL if the item doesn't exist
*/
public function item($item, $index = '')
{
if ($index == '')
{
return isset($this->config[$item]) ? $this->config[$item] : NULL;
}
return isset($this->config[$index], $this->config[$index][$item]) ? $this->config[$index][$item] : NULL;
}
// --------------------------------------------------------------------
/**
* Fetch a config file item with slash appended (if not empty)
*
* @param string $item Config item name
* @return string|null The configuration item or NULL if the item doesn't exist
*/
public function slash_item($item)
{
if ( ! isset($this->config[$item]))
{
return NULL;
}
elseif (trim($this->config[$item]) === '')
{
return '';
}
return rtrim($this->config[$item], '/').'/';
}
// --------------------------------------------------------------------
/**
* Site URL
*
* Returns base_url . index_page [. uri_string]
*
* @uses CI_Config::_uri_string()
*
* @param string|string[] $uri URI string or an array of segments
* @param string $protocol
* @return string
*/
public function site_url($uri = '', $protocol = NULL)
{
$base_url = $this->slash_item('base_url');
if (isset($protocol))
{
// For protocol-relative links
if ($protocol === '')
{
$base_url = substr($base_url, strpos($base_url, '//'));
}
else
{
$base_url = $protocol.substr($base_url, strpos($base_url, '://'));
}
}
if (empty($uri))
{
return $base_url.$this->item('index_page');
}
$uri = $this->_uri_string($uri);
if ($this->item('enable_query_strings') === FALSE)
{
$suffix = isset($this->config['url_suffix']) ? $this->config['url_suffix'] : '';
if ($suffix !== '')
{
if (($offset = strpos($uri, '?')) !== FALSE)
{
$uri = substr($uri, 0, $offset).$suffix.substr($uri, $offset);
}
else
{
$uri .= $suffix;
}
}
return $base_url.$this->slash_item('index_page').$uri;
}
elseif (strpos($uri, '?') === FALSE)
{
$uri = '?'.$uri;
}
return $base_url.$this->item('index_page').$uri;
}
// -------------------------------------------------------------
/**
* Base URL
*
* Returns base_url [. uri_string]
*
* @uses CI_Config::_uri_string()
*
* @param string|string[] $uri URI string or an array of segments
* @param string $protocol
* @return string
*/
public function base_url($uri = '', $protocol = NULL)
{
$base_url = $this->slash_item('base_url');
if (isset($protocol))
{
// For protocol-relative links
if ($protocol === '')
{
$base_url = substr($base_url, strpos($base_url, '//'));
}
else
{
$base_url = $protocol.substr($base_url, strpos($base_url, '://'));
}
}
return $base_url.$this->_uri_string($uri);
}
// -------------------------------------------------------------
/**
* Build URI string
*
* @used-by CI_Config::site_url()
* @used-by CI_Config::base_url()
*
* @param string|string[] $uri URI string or an array of segments
* @return string
*/
protected function _uri_string($uri)
{
if ($this->item('enable_query_strings') === FALSE)
{
is_array($uri) && $uri = implode('/', $uri);
return ltrim($uri, '/');
}
elseif (is_array($uri))
{
return http_build_query($uri);
}
return $uri;
}
// --------------------------------------------------------------------
/**
* System URL
*
* @deprecated 3.0.0 Encourages insecure practices
* @return string
*/
public function system_url()
{
$x = explode('/', preg_replace('|/*(.+?)/*$|', '\\1', BASEPATH));
return $this->slash_item('base_url').end($x).'/';
}
// --------------------------------------------------------------------
/**
* Set a config file item
*
* @param string $item Config item key
* @param string $value Config item value
* @return void
*/
public function set_item($item, $value)
{
$this->config[$item] = $value;
}
}

@ -0,0 +1,96 @@
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014 - 2017, British Columbia Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
* @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
* @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 1.0.0
* @filesource
*/
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Application Controller Class
*
* This class object is the super class that every library in
* CodeIgniter will be assigned to.
*
* @package CodeIgniter
* @subpackage Libraries
* @category Libraries
* @author EllisLab Dev Team
* @link https://codeigniter.com/user_guide/general/controllers.html
*/
class CI_Controller {
/**
* Reference to the CI singleton
*
* @var object
*/
private static $instance;
/**
* Class constructor
*
* @return void
*/
public function __construct()
{
self::$instance =& $this;
// Assign all the class objects that were instantiated by the
// bootstrap file (CodeIgniter.php) to local class variables
// so that CI can run as one big super object.
foreach (is_loaded() as $var => $class)
{
$this->$var =& load_class($class);
}
$this->load =& load_class('Loader', 'core');
$this->load->initialize();
log_message('info', 'Controller Class Initialized');
}
// --------------------------------------------------------------------
/**
* Get the CI singleton
*
* @static
* @return object
*/
public static function &get_instance()
{
return self::$instance;
}
}

@ -0,0 +1,274 @@
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014 - 2017, British Columbia Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
* @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
* @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 1.0.0
* @filesource
*/
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Exceptions Class
*
* @package CodeIgniter
* @subpackage Libraries
* @category Exceptions
* @author EllisLab Dev Team
* @link https://codeigniter.com/user_guide/libraries/exceptions.html
*/
class CI_Exceptions {
/**
* Nesting level of the output buffering mechanism
*
* @var int
*/
public $ob_level;
/**
* List of available error levels
*
* @var array
*/
public $levels = array(
E_ERROR => 'Error',
E_WARNING => 'Warning',
E_PARSE => 'Parsing Error',
E_NOTICE => 'Notice',
E_CORE_ERROR => 'Core Error',
E_CORE_WARNING => 'Core Warning',
E_COMPILE_ERROR => 'Compile Error',
E_COMPILE_WARNING => 'Compile Warning',
E_USER_ERROR => 'User Error',
E_USER_WARNING => 'User Warning',
E_USER_NOTICE => 'User Notice',
E_STRICT => 'Runtime Notice'
);
/**
* Class constructor
*
* @return void
*/
public function __construct()
{
$this->ob_level = ob_get_level();
// Note: Do not log messages from this constructor.
}
// --------------------------------------------------------------------
/**
* Exception Logger
*
* Logs PHP generated error messages
*
* @param int $severity Log level
* @param string $message Error message
* @param string $filepath File path
* @param int $line Line number
* @return void
*/
public function log_exception($severity, $message, $filepath, $line)
{
$severity = isset($this->levels[$severity]) ? $this->levels[$severity] : $severity;
log_message('error', 'Severity: '.$severity.' --> '.$message.' '.$filepath.' '.$line);
}
// --------------------------------------------------------------------
/**
* 404 Error Handler
*
* @uses CI_Exceptions::show_error()
*
* @param string $page Page URI
* @param bool $log_error Whether to log the error
* @return void
*/
public function show_404($page = '', $log_error = TRUE)
{
if (is_cli())
{
$heading = 'Not Found';
$message = 'The controller/method pair you requested was not found.';
}
else
{
$heading = '404 Page Not Found';
$message = 'The page you requested was not found.';
}
// By default we log this, but allow a dev to skip it
if ($log_error)
{
log_message('error', $heading.': '.$page);
}
echo $this->show_error($heading, $message, 'error_404', 404);
exit(4); // EXIT_UNKNOWN_FILE
}
// --------------------------------------------------------------------
/**
* General Error Page
*
* Takes an error message as input (either as a string or an array)
* and displays it using the specified template.
*
* @param string $heading Page heading
* @param string|string[] $message Error message
* @param string $template Template name
* @param int $status_code (default: 500)
*
* @return string Error page output
*/
public function show_error($heading, $message, $template = 'error_general', $status_code = 500)
{
$templates_path = config_item('error_views_path');
if (empty($templates_path))
{
$templates_path = VIEWPATH.'errors'.DIRECTORY_SEPARATOR;
}
if (is_cli())
{
$message = "\t".(is_array($message) ? implode("\n\t", $message) : $message);
$template = 'cli'.DIRECTORY_SEPARATOR.$template;
}
else
{
set_status_header($status_code);
$message = '<p>'.(is_array($message) ? implode('</p><p>', $message) : $message).'</p>';
$template = 'html'.DIRECTORY_SEPARATOR.$template;
}
if (ob_get_level() > $this->ob_level + 1)
{
ob_end_flush();
}
ob_start();
include($templates_path.$template.'.php');
$buffer = ob_get_contents();
ob_end_clean();
return $buffer;
}
// --------------------------------------------------------------------
public function show_exception($exception)
{
$templates_path = config_item('error_views_path');
if (empty($templates_path))
{
$templates_path = VIEWPATH.'errors'.DIRECTORY_SEPARATOR;
}
$message = $exception->getMessage();
if (empty($message))
{
$message = '(null)';
}
if (is_cli())
{
$templates_path .= 'cli'.DIRECTORY_SEPARATOR;
}
else
{
$templates_path .= 'html'.DIRECTORY_SEPARATOR;
}
if (ob_get_level() > $this->ob_level + 1)
{
ob_end_flush();
}
ob_start();
include($templates_path.'error_exception.php');
$buffer = ob_get_contents();
ob_end_clean();
echo $buffer;
}
// --------------------------------------------------------------------
/**
* Native PHP error handler
*
* @param int $severity Error level
* @param string $message Error message
* @param string $filepath File path
* @param int $line Line number
* @return void
*/
public function show_php_error($severity, $message, $filepath, $line)
{
$templates_path = config_item('error_views_path');
if (empty($templates_path))
{
$templates_path = VIEWPATH.'errors'.DIRECTORY_SEPARATOR;
}
$severity = isset($this->levels[$severity]) ? $this->levels[$severity] : $severity;
// For safety reasons we don't show the full file path in non-CLI requests
if ( ! is_cli())
{
$filepath = str_replace('\\', '/', $filepath);
if (FALSE !== strpos($filepath, '/'))
{
$x = explode('/', $filepath);
$filepath = $x[count($x)-2].'/'.end($x);
}
$template = 'html'.DIRECTORY_SEPARATOR.'error_php';
}
else
{
$template = 'cli'.DIRECTORY_SEPARATOR.'error_php';
}
if (ob_get_level() > $this->ob_level + 1)
{
ob_end_flush();
}
ob_start();
include($templates_path.$template.'.php');
$buffer = ob_get_contents();
ob_end_clean();
echo $buffer;
}
}

@ -0,0 +1,266 @@
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014 - 2017, British Columbia Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
* @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
* @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 1.0.0
* @filesource
*/
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Hooks Class
*
* Provides a mechanism to extend the base system without hacking.
*
* @package CodeIgniter
* @subpackage Libraries
* @category Libraries
* @author EllisLab Dev Team
* @link https://codeigniter.com/user_guide/general/hooks.html
*/
class CI_Hooks {
/**
* Determines whether hooks are enabled
*
* @var bool
*/
public $enabled = FALSE;
/**
* List of all hooks set in config/hooks.php
*
* @var array
*/
public $hooks = array();
/**
* Array with class objects to use hooks methods
*
* @var array
*/
protected $_objects = array();
/**
* In progress flag
*
* Determines whether hook is in progress, used to prevent infinte loops
*
* @var bool
*/
protected $_in_progress = FALSE;
/**
* Class constructor
*
* @return void
*/
public function __construct()
{
$CFG =& load_class('Config', 'core');
log_message('info', 'Hooks Class Initialized');
// If hooks are not enabled in the config file
// there is nothing else to do
if ($CFG->item('enable_hooks') === FALSE)
{
return;
}
// Grab the "hooks" definition file.
if (file_exists(APPPATH.'config/hooks.php'))
{
include(APPPATH.'config/hooks.php');
}
if (file_exists(APPPATH.'config/'.ENVIRONMENT.'/hooks.php'))
{
include(APPPATH.'config/'.ENVIRONMENT.'/hooks.php');
}
// If there are no hooks, we're done.
if ( ! isset($hook) OR ! is_array($hook))
{
return;
}
$this->hooks =& $hook;
$this->enabled = TRUE;
}
// --------------------------------------------------------------------
/**
* Call Hook
*
* Calls a particular hook. Called by CodeIgniter.php.
*
* @uses CI_Hooks::_run_hook()
*
* @param string $which Hook name
* @return bool TRUE on success or FALSE on failure
*/
public function call_hook($which = '')
{
if ( ! $this->enabled OR ! isset($this->hooks[$which]))
{
return FALSE;
}
if (is_array($this->hooks[$which]) && ! isset($this->hooks[$which]['function']))
{
foreach ($this->hooks[$which] as $val)
{
$this->_run_hook($val);
}
}
else
{
$this->_run_hook($this->hooks[$which]);
}
return TRUE;
}
// --------------------------------------------------------------------
/**
* Run Hook
*
* Runs a particular hook
*
* @param array $data Hook details
* @return bool TRUE on success or FALSE on failure
*/
protected function _run_hook($data)
{
// Closures/lambda functions and array($object, 'method') callables
if (is_callable($data))
{
is_array($data)
? $data[0]->{$data[1]}()
: $data();
return TRUE;
}
elseif ( ! is_array($data))
{
return FALSE;
}
// -----------------------------------
// Safety - Prevents run-away loops
// -----------------------------------
// If the script being called happens to have the same
// hook call within it a loop can happen
if ($this->_in_progress === TRUE)
{
return;
}
// -----------------------------------
// Set file path
// -----------------------------------
if ( ! isset($data['filepath'], $data['filename']))
{
return FALSE;
}
$filepath = APPPATH.$data['filepath'].'/'.$data['filename'];
if ( ! file_exists($filepath))
{
return FALSE;
}
// Determine and class and/or function names
$class = empty($data['class']) ? FALSE : $data['class'];
$function = empty($data['function']) ? FALSE : $data['function'];
$params = isset($data['params']) ? $data['params'] : '';
if (empty($function))
{
return FALSE;
}
// Set the _in_progress flag
$this->_in_progress = TRUE;
// Call the requested class and/or function
if ($class !== FALSE)
{
// The object is stored?
if (isset($this->_objects[$class]))
{
if (method_exists($this->_objects[$class], $function))
{
$this->_objects[$class]->$function($params);
}
else
{
return $this->_in_progress = FALSE;
}
}
else
{
class_exists($class, FALSE) OR require_once($filepath);
if ( ! class_exists($class, FALSE) OR ! method_exists($class, $function))
{
return $this->_in_progress = FALSE;
}
// Store the object and execute the method
$this->_objects[$class] = new $class();
$this->_objects[$class]->$function($params);
}
}
else
{
function_exists($function) OR require_once($filepath);
if ( ! function_exists($function))
{
return $this->_in_progress = FALSE;
}
$function($params);
}
$this->_in_progress = FALSE;
return TRUE;
}
}

@ -0,0 +1,895 @@
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014 - 2017, British Columbia Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
* @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
* @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 1.0.0
* @filesource
*/
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Input Class
*
* Pre-processes global input data for security
*
* @package CodeIgniter
* @subpackage Libraries
* @category Input
* @author EllisLab Dev Team
* @link https://codeigniter.com/user_guide/libraries/input.html
*/
class CI_Input {
/**
* IP address of the current user
*
* @var string
*/
protected $ip_address = FALSE;
/**
* Allow GET array flag
*
* If set to FALSE, then $_GET will be set to an empty array.
*
* @var bool
*/
protected $_allow_get_array = TRUE;
/**
* Standardize new lines flag
*
* If set to TRUE, then newlines are standardized.
*
* @var bool
*/
protected $_standardize_newlines;
/**
* Enable XSS flag
*
* Determines whether the XSS filter is always active when
* GET, POST or COOKIE data is encountered.
* Set automatically based on config setting.
*
* @var bool
*/
protected $_enable_xss = FALSE;
/**
* Enable CSRF flag
*
* Enables a CSRF cookie token to be set.
* Set automatically based on config setting.
*
* @var bool
*/
protected $_enable_csrf = FALSE;
/**
* List of all HTTP request headers
*
* @var array
*/
protected $headers = array();
/**
* Raw input stream data
*
* Holds a cache of php://input contents
*
* @var string
*/
protected $_raw_input_stream;
/**
* Parsed input stream data
*
* Parsed from php://input at runtime
*
* @see CI_Input::input_stream()
* @var array
*/
protected $_input_stream;
protected $security;
protected $uni;
// --------------------------------------------------------------------
/**
* Class constructor
*
* Determines whether to globally enable the XSS processing
* and whether to allow the $_GET array.
*
* @return void
*/
public function __construct()
{
$this->_allow_get_array = (config_item('allow_get_array') === TRUE);
$this->_enable_xss = (config_item('global_xss_filtering') === TRUE);
$this->_enable_csrf = (config_item('csrf_protection') === TRUE);
$this->_standardize_newlines = (bool) config_item('standardize_newlines');
$this->security =& load_class('Security', 'core');
// Do we need the UTF-8 class?
if (UTF8_ENABLED === TRUE)
{
$this->uni =& load_class('Utf8', 'core');
}
// Sanitize global arrays
$this->_sanitize_globals();
// CSRF Protection check
if ($this->_enable_csrf === TRUE && ! is_cli())
{
$this->security->csrf_verify();
}
log_message('info', 'Input Class Initialized');
}
// --------------------------------------------------------------------
/**
* Fetch from array
*
* Internal method used to retrieve values from global arrays.
*
* @param array &$array $_GET, $_POST, $_COOKIE, $_SERVER, etc.
* @param mixed $index Index for item to be fetched from $array
* @param bool $xss_clean Whether to apply XSS filtering
* @return mixed
*/
protected function _fetch_from_array(&$array, $index = NULL, $xss_clean = NULL)
{
is_bool($xss_clean) OR $xss_clean = $this->_enable_xss;
// If $index is NULL, it means that the whole $array is requested
isset($index) OR $index = array_keys($array);
// allow fetching multiple keys at once
if (is_array($index))
{
$output = array();
foreach ($index as $key)
{
$output[$key] = $this->_fetch_from_array($array, $key, $xss_clean);
}
return $output;
}
if (isset($array[$index]))
{
$value = $array[$index];
}
elseif (($count = preg_match_all('/(?:^[^\[]+)|\[[^]]*\]/', $index, $matches)) > 1) // Does the index contain array notation
{
$value = $array;
for ($i = 0; $i < $count; $i++)
{
$key = trim($matches[0][$i], '[]');
if ($key === '') // Empty notation will return the value as array
{
break;
}
if (isset($value[$key]))
{
$value = $value[$key];
}
else
{
return NULL;
}
}
}
else
{
return NULL;
}
return ($xss_clean === TRUE)
? $this->security->xss_clean($value)
: $value;
}
// --------------------------------------------------------------------
/**
* Fetch an item from the GET array
*
* @param mixed $index Index for item to be fetched from $_GET
* @param bool $xss_clean Whether to apply XSS filtering
* @return mixed
*/
public function get($index = NULL, $xss_clean = NULL)
{
return $this->_fetch_from_array($_GET, $index, $xss_clean);
}
// --------------------------------------------------------------------
/**
* Fetch an item from the POST array
*
* @param mixed $index Index for item to be fetched from $_POST
* @param bool $xss_clean Whether to apply XSS filtering
* @return mixed
*/
public function post($index = NULL, $xss_clean = NULL)
{
return $this->_fetch_from_array($_POST, $index, $xss_clean);
}
// --------------------------------------------------------------------
/**
* Fetch an item from POST data with fallback to GET
*
* @param string $index Index for item to be fetched from $_POST or $_GET
* @param bool $xss_clean Whether to apply XSS filtering
* @return mixed
*/
public function post_get($index, $xss_clean = NULL)
{
return isset($_POST[$index])
? $this->post($index, $xss_clean)
: $this->get($index, $xss_clean);
}
// --------------------------------------------------------------------
/**
* Fetch an item from GET data with fallback to POST
*
* @param string $index Index for item to be fetched from $_GET or $_POST
* @param bool $xss_clean Whether to apply XSS filtering
* @return mixed
*/
public function get_post($index, $xss_clean = NULL)
{
return isset($_GET[$index])
? $this->get($index, $xss_clean)
: $this->post($index, $xss_clean);
}
// --------------------------------------------------------------------
/**
* Fetch an item from the COOKIE array
*
* @param mixed $index Index for item to be fetched from $_COOKIE
* @param bool $xss_clean Whether to apply XSS filtering
* @return mixed
*/
public function cookie($index = NULL, $xss_clean = NULL)
{
return $this->_fetch_from_array($_COOKIE, $index, $xss_clean);
}
// --------------------------------------------------------------------
/**
* Fetch an item from the SERVER array
*
* @param mixed $index Index for item to be fetched from $_SERVER
* @param bool $xss_clean Whether to apply XSS filtering
* @return mixed
*/
public function server($index, $xss_clean = NULL)
{
return $this->_fetch_from_array($_SERVER, $index, $xss_clean);
}
// ------------------------------------------------------------------------
/**
* Fetch an item from the php://input stream
*
* Useful when you need to access PUT, DELETE or PATCH request data.
*
* @param string $index Index for item to be fetched
* @param bool $xss_clean Whether to apply XSS filtering
* @return mixed
*/
public function input_stream($index = NULL, $xss_clean = NULL)
{
// Prior to PHP 5.6, the input stream can only be read once,
// so we'll need to check if we have already done that first.
if ( ! is_array($this->_input_stream))
{
// $this->raw_input_stream will trigger __get().
parse_str($this->raw_input_stream, $this->_input_stream);
is_array($this->_input_stream) OR $this->_input_stream = array();
}
return $this->_fetch_from_array($this->_input_stream, $index, $xss_clean);
}
// ------------------------------------------------------------------------
/**
* Set cookie
*
* Accepts an arbitrary number of parameters (up to 7) or an associative
* array in the first parameter containing all the values.
*
* @param string|mixed[] $name Cookie name or an array containing parameters
* @param string $value Cookie value
* @param int $expire Cookie expiration time in seconds
* @param string $domain Cookie domain (e.g.: '.yourdomain.com')
* @param string $path Cookie path (default: '/')
* @param string $prefix Cookie name prefix
* @param bool $secure Whether to only transfer cookies via SSL
* @param bool $httponly Whether to only makes the cookie accessible via HTTP (no javascript)
* @return void
*/
public function set_cookie($name, $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = NULL, $httponly = NULL)
{
if (is_array($name))
{
// always leave 'name' in last place, as the loop will break otherwise, due to $$item
foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'secure', 'httponly', 'name') as $item)
{
if (isset($name[$item]))
{
$$item = $name[$item];
}
}
}
if ($prefix === '' && config_item('cookie_prefix') !== '')
{
$prefix = config_item('cookie_prefix');
}
if ($domain == '' && config_item('cookie_domain') != '')
{
$domain = config_item('cookie_domain');
}
if ($path === '/' && config_item('cookie_path') !== '/')
{
$path = config_item('cookie_path');
}
$secure = ($secure === NULL && config_item('cookie_secure') !== NULL)
? (bool) config_item('cookie_secure')
: (bool) $secure;
$httponly = ($httponly === NULL && config_item('cookie_httponly') !== NULL)
? (bool) config_item('cookie_httponly')
: (bool) $httponly;
if ( ! is_numeric($expire))
{
$expire = time() - 86500;
}
else
{
$expire = ($expire > 0) ? time() + $expire : 0;
}
setcookie($prefix.$name, $value, $expire, $path, $domain, $secure, $httponly);
}
// --------------------------------------------------------------------
/**
* Fetch the IP Address
*
* Determines and validates the visitor's IP address.
*
* @return string IP address
*/
public function ip_address()
{
if ($this->ip_address !== FALSE)
{
return $this->ip_address;
}
$proxy_ips = config_item('proxy_ips');
if ( ! empty($proxy_ips) && ! is_array($proxy_ips))
{
$proxy_ips = explode(',', str_replace(' ', '', $proxy_ips));
}
$this->ip_address = $this->server('REMOTE_ADDR');
if ($proxy_ips)
{
foreach (array('HTTP_X_FORWARDED_FOR', 'HTTP_CLIENT_IP', 'HTTP_X_CLIENT_IP', 'HTTP_X_CLUSTER_CLIENT_IP') as $header)
{
if (($spoof = $this->server($header)) !== NULL)
{
// Some proxies typically list the whole chain of IP
// addresses through which the client has reached us.
// e.g. client_ip, proxy_ip1, proxy_ip2, etc.
sscanf($spoof, '%[^,]', $spoof);
if ( ! $this->valid_ip($spoof))
{
$spoof = NULL;
}
else
{
break;
}
}
}
if ($spoof)
{
for ($i = 0, $c = count($proxy_ips); $i < $c; $i++)
{
// Check if we have an IP address or a subnet
if (strpos($proxy_ips[$i], '/') === FALSE)
{
// An IP address (and not a subnet) is specified.
// We can compare right away.
if ($proxy_ips[$i] === $this->ip_address)
{
$this->ip_address = $spoof;
break;
}
continue;
}
// We have a subnet ... now the heavy lifting begins
isset($separator) OR $separator = $this->valid_ip($this->ip_address, 'ipv6') ? ':' : '.';
// If the proxy entry doesn't match the IP protocol - skip it
if (strpos($proxy_ips[$i], $separator) === FALSE)
{
continue;
}
// Convert the REMOTE_ADDR IP address to binary, if needed
if ( ! isset($ip, $sprintf))
{
if ($separator === ':')
{
// Make sure we're have the "full" IPv6 format
$ip = explode(':',
str_replace('::',
str_repeat(':', 9 - substr_count($this->ip_address, ':')),
$this->ip_address
)
);
for ($j = 0; $j < 8; $j++)
{
$ip[$j] = intval($ip[$j], 16);
}
$sprintf = '%016b%016b%016b%016b%016b%016b%016b%016b';
}
else
{
$ip = explode('.', $this->ip_address);
$sprintf = '%08b%08b%08b%08b';
}
$ip = vsprintf($sprintf, $ip);
}
// Split the netmask length off the network address
sscanf($proxy_ips[$i], '%[^/]/%d', $netaddr, $masklen);
// Again, an IPv6 address is most likely in a compressed form
if ($separator === ':')
{
$netaddr = explode(':', str_replace('::', str_repeat(':', 9 - substr_count($netaddr, ':')), $netaddr));
for ($j = 0; $j < 8; $j++)
{
$netaddr[$j] = intval($netaddr[$j], 16);
}
}
else
{
$netaddr = explode('.', $netaddr);
}
// Convert to binary and finally compare
if (strncmp($ip, vsprintf($sprintf, $netaddr), $masklen) === 0)
{
$this->ip_address = $spoof;
break;
}
}
}
}
if ( ! $this->valid_ip($this->ip_address))
{
return $this->ip_address = '0.0.0.0';
}
return $this->ip_address;
}
// --------------------------------------------------------------------
/**
* Validate IP Address
*
* @param string $ip IP address
* @param string $which IP protocol: 'ipv4' or 'ipv6'
* @return bool
*/
public function valid_ip($ip, $which = '')
{
switch (strtolower($which))
{
case 'ipv4':
$which = FILTER_FLAG_IPV4;
break;
case 'ipv6':
$which = FILTER_FLAG_IPV6;
break;
default:
$which = NULL;
break;
}
return (bool) filter_var($ip, FILTER_VALIDATE_IP, $which);
}
// --------------------------------------------------------------------
/**
* Fetch User Agent string
*
* @return string|null User Agent string or NULL if it doesn't exist
*/
public function user_agent($xss_clean = NULL)
{
return $this->_fetch_from_array($_SERVER, 'HTTP_USER_AGENT', $xss_clean);
}
// --------------------------------------------------------------------
/**
* Sanitize Globals
*
* Internal method serving for the following purposes:
*
* - Unsets $_GET data, if query strings are not enabled
* - Cleans POST, COOKIE and SERVER data
* - Standardizes newline characters to PHP_EOL
*
* @return void
*/
protected function _sanitize_globals()
{
// Is $_GET data allowed? If not we'll set the $_GET to an empty array
if ($this->_allow_get_array === FALSE)
{
$_GET = array();
}
elseif (is_array($_GET))
{
foreach ($_GET as $key => $val)
{
$_GET[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
}
}
// Clean $_POST Data
if (is_array($_POST))
{
foreach ($_POST as $key => $val)
{
$_POST[$this->_clean_input_keys($key)] = $this->_clean_input_data($val);
}
}
// Clean $_COOKIE Data
if (is_array($_COOKIE))
{
// Also get rid of specially treated cookies that might be set by a server
// or silly application, that are of no use to a CI application anyway
// but that when present will trip our 'Disallowed Key Characters' alarm
// http://www.ietf.org/rfc/rfc2109.txt
// note that the key names below are single quoted strings, and are not PHP variables
unset(
$_COOKIE['$Version'],
$_COOKIE['$Path'],
$_COOKIE['$Domain']
);
foreach ($_COOKIE as $key => $val)
{
if (($cookie_key = $this->_clean_input_keys($key)) !== FALSE)
{
$_COOKIE[$cookie_key] = $this->_clean_input_data($val);
}
else
{
unset($_COOKIE[$key]);
}
}
}
// Sanitize PHP_SELF
$_SERVER['PHP_SELF'] = strip_tags($_SERVER['PHP_SELF']);
log_message('debug', 'Global POST, GET and COOKIE data sanitized');
}
// --------------------------------------------------------------------
/**
* Clean Input Data
*
* Internal method that aids in escaping data and
* standardizing newline characters to PHP_EOL.
*
* @param string|string[] $str Input string(s)
* @return string
*/
protected function _clean_input_data($str)
{
if (is_array($str))
{
$new_array = array();
foreach (array_keys($str) as $key)
{
$new_array[$this->_clean_input_keys($key)] = $this->_clean_input_data($str[$key]);
}
return $new_array;
}
/* We strip slashes if magic quotes is on to keep things consistent
NOTE: In PHP 5.4 get_magic_quotes_gpc() will always return 0 and
it will probably not exist in future versions at all.
*/
if ( ! is_php('5.4') && get_magic_quotes_gpc())
{
$str = stripslashes($str);
}
// Clean UTF-8 if supported
if (UTF8_ENABLED === TRUE)
{
$str = $this->uni->clean_string($str);
}
// Remove control characters
$str = remove_invisible_characters($str, FALSE);
// Standardize newlines if needed
if ($this->_standardize_newlines === TRUE)
{
return preg_replace('/(?:\r\n|[\r\n])/', PHP_EOL, $str);
}
return $str;
}
// --------------------------------------------------------------------
/**
* Clean Keys
*
* Internal method that helps to prevent malicious users
* from trying to exploit keys we make sure that keys are
* only named with alpha-numeric text and a few other items.
*
* @param string $str Input string
* @param bool $fatal Whether to terminate script exection
* or to return FALSE if an invalid
* key is encountered
* @return string|bool
*/
protected function _clean_input_keys($str, $fatal = TRUE)
{
if ( ! preg_match('/^[a-z0-9:_\/|-]+$/i', $str))
{
if ($fatal === TRUE)
{
return FALSE;
}
else
{
set_status_header(503);
echo 'Disallowed Key Characters.';
exit(7); // EXIT_USER_INPUT
}
}
// Clean UTF-8 if supported
if (UTF8_ENABLED === TRUE)
{
return $this->uni->clean_string($str);
}
return $str;
}
// --------------------------------------------------------------------
/**
* Request Headers
*
* @param bool $xss_clean Whether to apply XSS filtering
* @return array
*/
public function request_headers($xss_clean = FALSE)
{
// If header is already defined, return it immediately
if ( ! empty($this->headers))
{
return $this->_fetch_from_array($this->headers, NULL, $xss_clean);
}
// In Apache, you can simply call apache_request_headers()
if (function_exists('apache_request_headers'))
{
$this->headers = apache_request_headers();
}
else
{
isset($_SERVER['CONTENT_TYPE']) && $this->headers['Content-Type'] = $_SERVER['CONTENT_TYPE'];
foreach ($_SERVER as $key => $val)
{
if (sscanf($key, 'HTTP_%s', $header) === 1)
{
// take SOME_HEADER and turn it into Some-Header
$header = str_replace('_', ' ', strtolower($header));
$header = str_replace(' ', '-', ucwords($header));
$this->headers[$header] = $_SERVER[$key];
}
}
}
return $this->_fetch_from_array($this->headers, NULL, $xss_clean);
}
// --------------------------------------------------------------------
/**
* Get Request Header
*
* Returns the value of a single member of the headers class member
*
* @param string $index Header name
* @param bool $xss_clean Whether to apply XSS filtering
* @return string|null The requested header on success or NULL on failure
*/
public function get_request_header($index, $xss_clean = FALSE)
{
static $headers;
if ( ! isset($headers))
{
empty($this->headers) && $this->request_headers();
foreach ($this->headers as $key => $value)
{
$headers[strtolower($key)] = $value;
}
}
$index = strtolower($index);
if ( ! isset($headers[$index]))
{
return NULL;
}
return ($xss_clean === TRUE)
? $this->security->xss_clean($headers[$index])
: $headers[$index];
}
// --------------------------------------------------------------------
/**
* Is AJAX request?
*
* Test to see if a request contains the HTTP_X_REQUESTED_WITH header.
*
* @return bool
*/
public function is_ajax_request()
{
return ( ! empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) === 'xmlhttprequest');
}
// --------------------------------------------------------------------
/**
* Is CLI request?
*
* Test to see if a request was made from the command line.
*
* @deprecated 3.0.0 Use is_cli() instead
* @return bool
*/
public function is_cli_request()
{
return is_cli();
}
// --------------------------------------------------------------------
/**
* Get Request Method
*
* Return the request method
*
* @param bool $upper Whether to return in upper or lower case
* (default: FALSE)
* @return string
*/
public function method($upper = FALSE)
{
return ($upper)
? strtoupper($this->server('REQUEST_METHOD'))
: strtolower($this->server('REQUEST_METHOD'));
}
// ------------------------------------------------------------------------
/**
* Magic __get()
*
* Allows read access to protected properties
*
* @param string $name
* @return mixed
*/
public function __get($name)
{
if ($name === 'raw_input_stream')
{
isset($this->_raw_input_stream) OR $this->_raw_input_stream = file_get_contents('php://input');
return $this->_raw_input_stream;
}
elseif ($name === 'ip_address')
{
return $this->ip_address;
}
}
}

@ -0,0 +1,203 @@
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP
*
* This content is released under the MIT License (MIT)
*
* Copyright (c) 2014 - 2017, British Columbia Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @package CodeIgniter
* @author EllisLab Dev Team
* @copyright Copyright (c) 2008 - 2014, EllisLab, Inc. (https://ellislab.com/)
* @copyright Copyright (c) 2014 - 2017, British Columbia Institute of Technology (http://bcit.ca/)
* @license http://opensource.org/licenses/MIT MIT License
* @link https://codeigniter.com
* @since Version 1.0.0
* @filesource
*/
defined('BASEPATH') OR exit('No direct script access allowed');
/**
* Language Class
*
* @package CodeIgniter
* @subpackage Libraries
* @category Language
* @author EllisLab Dev Team
* @link https://codeigniter.com/user_guide/libraries/language.html
*/
class CI_Lang {
/**
* List of translations
*
* @var array
*/
public $language = array();
/**
* List of loaded language files
*
* @var array
*/
public $is_loaded = array();
/**
* Class constructor
*
* @return void
*/
public function __construct()
{
log_message('info', 'Language Class Initialized');
}
// --------------------------------------------------------------------
/**
* Load a language file
*
* @param mixed $langfile Language file name
* @param string $idiom Language name (english, etc.)
* @param bool $return Whether to return the loaded array of translations
* @param bool $add_suffix Whether to add suffix to $langfile
* @param string $alt_path Alternative path to look for the language file
*
* @return void|string[] Array containing translations, if $return is set to TRUE
*/
public function load($langfile, $idiom = '', $return = FALSE, $add_suffix = TRUE, $alt_path = '')
{
if (is_array($langfile))
{
foreach ($langfile as $value)
{
$this->load($value, $idiom, $return, $add_suffix, $alt_path);
}
return;
}
$langfile = str_replace('.php', '', $langfile);
if ($add_suffix === TRUE)
{
$langfile = preg_replace('/_lang$/', '', $langfile).'_lang';
}
$langfile .= '.php';
if (empty($idiom) OR ! preg_match('/^[a-z_-]+$/i', $idiom))
{
$config =& get_config();
$idiom = empty($config['language']) ? 'english' : $config['language'];
}
if ($return === FALSE && isset($this->is_loaded[$langfile]) && $this->is_loaded[$langfile] === $idiom)
{
return;
}
// Load the base file, so any others found can override it
$basepath = BASEPATH.'language/'.$idiom.'/'.$langfile;
if (($found = file_exists($basepath)) === TRUE)
{
include($basepath);
}
// Do we have an alternative path to look in?
if ($alt_path !== '')
{
$alt_path .= 'language/'.$idiom.'/'.$langfile;
if (file_exists($alt_path))
{
include($alt_path);
$found = TRUE;
}
}
else
{
foreach (get_instance()->load->get_package_paths(TRUE) as $package_path)
{
$package_path .= 'language/'.$idiom.'/'.$langfile;
if ($basepath !== $package_path && file_exists($package_path))
{
include($package_path);
$found = TRUE;
break;
}
}
}
if ($found !== TRUE)
{
show_error('Unable to load the requested language file: language/'.$idiom.'/'.$langfile);
}
if ( ! isset($lang) OR ! is_array($lang))
{
log_message('error', 'Language file contains no data: language/'.$idiom.'/'.$langfile);
if ($return === TRUE)
{
return array();
}
return;
}
if ($return === TRUE)
{
return $lang;
}
$this->is_loaded[$langfile] = $idiom;
$this->language = array_merge($this->language, $lang);
log_message('info', 'Language file loaded: language/'.$idiom.'/'.$langfile);
return TRUE;
}
// --------------------------------------------------------------------
/**
* Language line
*
* Fetches a single line of text from the language array
*
* @param string $line Language line key
* @param bool $log_errors Whether to log an error message if the line is not found
* @return string Translation
*/
public function line($line, $log_errors = TRUE)
{
$value = isset($this->language[$line]) ? $this->language[$line] : FALSE;
// Because killer robots like unicorns!
if ($value === FALSE && $log_errors === TRUE)
{
log_message('error', 'Could not find the language line "'.$line.'"');
}
return $value;
}
}

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save