diff --git a/CREDITS b/CREDITS new file mode 100644 index 0000000..c9d2c09 --- /dev/null +++ b/CREDITS @@ -0,0 +1 @@ +wxwork_finance_sdk diff --git a/EXPERIMENTAL b/EXPERIMENTAL new file mode 100644 index 0000000..e69de29 diff --git a/build.sh b/build.sh new file mode 100644 index 0000000..6c5f81a --- /dev/null +++ b/build.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +rm -f /tmp/core* + +make clean +make +sudo make install +/home/y/bin/php wxwork_finance_sdk.php + +ls -l /tmp/core* \ No newline at end of file diff --git a/config.m4 b/config.m4 new file mode 100644 index 0000000..d044af5 --- /dev/null +++ b/config.m4 @@ -0,0 +1,91 @@ +dnl $Id$ +dnl config.m4 for extension wxwork_finance_sdk + +dnl Comments in this file start with the string 'dnl'. +dnl Remove where necessary. This file will not work +dnl without editing. + +dnl If your extension references something external, use with: + +PHP_ARG_WITH(wxwork_finance_sdk, for wxwork_finance_sdk support, +dnl Make sure that the comment is aligned: +[ --with-wxwork_finance_sdk=DIR Include wxwork_finance_sdk support]) + +dnl Otherwise use enable: + + +if test "$PHP_WXWORK_FINANCE_SDK" != "no"; then + dnl check wxwork finance sdk is valid + + + AC_MSG_CHECKING($PHP_WXWORK_FINANCE_SDK) + if test -f "${PHP_WXWORK_FINANCE_SDK}/WeWorkFinanceSdk_C.h" && test -f "${PHP_WXWORK_FINANCE_SDK}/libWeWorkFinanceSdk_C.so"; then + AC_MSG_RESULT(yes) + else + AC_MSG_ERROR(cannot find WeWorkFinanceSdk_C.h in path ${PHP_WXWORK_FINANCE_SDK}) + fi + + PHP_ADD_INCLUDE($PHP_WXWORK_FINANCE_SDK) + PHP_ADD_LIBRARY_WITH_PATH(WeWorkFinanceSdk_C.so, $PHP_WXWORK_FINANCE_SDK, WXWORK_FINANCE_SDK_SHARED_LIBADD) + + dnl Write more examples of tests here... + + dnl # get library FOO build options from pkg-config output + dnl AC_PATH_PROG(PKG_CONFIG, pkg-config, no) + dnl AC_MSG_CHECKING(for libfoo) + dnl if test -x "$PKG_CONFIG" && $PKG_CONFIG --exists foo; then + dnl if $PKG_CONFIG foo --atleast-version 1.2.3; then + dnl LIBFOO_CFLAGS=`$PKG_CONFIG foo --cflags` + dnl LIBFOO_LIBDIR=`$PKG_CONFIG foo --libs` + dnl LIBFOO_VERSON=`$PKG_CONFIG foo --modversion` + dnl AC_MSG_RESULT(from pkgconfig: version $LIBFOO_VERSON) + dnl else + dnl AC_MSG_ERROR(system libfoo is too old: version 1.2.3 required) + dnl fi + dnl else + dnl AC_MSG_ERROR(pkg-config not found) + dnl fi + dnl PHP_EVAL_LIBLINE($LIBFOO_LIBDIR, WXWORK_FINANCE_SDK_SHARED_LIBADD) + dnl PHP_EVAL_INCLINE($LIBFOO_CFLAGS) + + dnl # --with-wxwork_finance_sdk -> check with-path + dnl SEARCH_PATH="/usr/local /usr" # you might want to change this + dnl SEARCH_FOR="/include/wxwork_finance_sdk.h" # you most likely want to change this + dnl if test -r $PHP_WXWORK_FINANCE_SDK/$SEARCH_FOR; then # path given as parameter + dnl WXWORK_FINANCE_SDK_DIR=$PHP_WXWORK_FINANCE_SDK + dnl else # search default path list + dnl AC_MSG_CHECKING([for wxwork_finance_sdk files in default path]) + dnl for i in $SEARCH_PATH ; do + dnl if test -r $i/$SEARCH_FOR; then + dnl WXWORK_FINANCE_SDK_DIR=$i + dnl AC_MSG_RESULT(found in $i) + dnl fi + dnl done + dnl fi + dnl + dnl if test -z "$WXWORK_FINANCE_SDK_DIR"; then + dnl AC_MSG_RESULT([not found]) + dnl AC_MSG_ERROR([Please reinstall the wxwork_finance_sdk distribution]) + dnl fi + + dnl # --with-wxwork_finance_sdk -> add include path + dnl PHP_ADD_INCLUDE($WXWORK_FINANCE_SDK_DIR/include) + + dnl # --with-wxwork_finance_sdk -> check for lib and symbol presence + dnl LIBNAME=wxwork_finance_sdk # you may want to change this + dnl LIBSYMBOL=wxwork_finance_sdk # you most likely want to change this + + dnl PHP_CHECK_LIBRARY($LIBNAME,$LIBSYMBOL, + dnl [ + dnl PHP_ADD_LIBRARY_WITH_PATH($LIBNAME, $WXWORK_FINANCE_SDK_DIR/$PHP_LIBDIR, WXWORK_FINANCE_SDK_SHARED_LIBADD) + dnl AC_DEFINE(HAVE_WXWORK_FINANCE_SDKLIB,1,[ ]) + dnl ],[ + dnl AC_MSG_ERROR([wrong wxwork_finance_sdk lib version or lib not found]) + dnl ],[ + dnl -L$WXWORK_FINANCE_SDK_DIR/$PHP_LIBDIR -lm + dnl ]) + dnl + dnl PHP_SUBST(WXWORK_FINANCE_SDK_SHARED_LIBADD) + + PHP_NEW_EXTENSION(wxwork_finance_sdk, wxwork_finance_sdk.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1) +fi diff --git a/config.w32 b/config.w32 new file mode 100644 index 0000000..59d7d85 --- /dev/null +++ b/config.w32 @@ -0,0 +1,13 @@ +// $Id$ +// vim:ft=javascript + +// If your extension references something external, use ARG_WITH +// ARG_WITH("wxwork_finance_sdk", "for wxwork_finance_sdk support", "no"); + +// Otherwise, use ARG_ENABLE +ARG_ENABLE("wxwork_finance_sdk", "enable wxwork_finance_sdk support", "no"); + +if (PHP_WXWORK_FINANCE_SDK != "no") { + EXTENSION("wxwork_finance_sdk", "wxwork_finance_sdk.c", PHP_EXTNAME_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1"); +} + diff --git a/php_wxwork_finance_sdk.h b/php_wxwork_finance_sdk.h new file mode 100644 index 0000000..0ae7714 --- /dev/null +++ b/php_wxwork_finance_sdk.h @@ -0,0 +1,85 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 7 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2018 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + +#ifndef PHP_WXWORK_FINANCE_SDK_H +#define PHP_WXWORK_FINANCE_SDK_H + +extern zend_module_entry wxwork_finance_sdk_module_entry; +#define phpext_wxwork_finance_sdk_ptr &wxwork_finance_sdk_module_entry + +#define PHP_WXWORK_FINANCE_SDK_VERSION "0.1.0" /* Replace with version number for your extension */ + +#ifdef PHP_WIN32 +# define PHP_WXWORK_FINANCE_SDK_API __declspec(dllexport) +#elif defined(__GNUC__) && __GNUC__ >= 4 +# define PHP_WXWORK_FINANCE_SDK_API __attribute__ ((visibility("default"))) +#else +# define PHP_WXWORK_FINANCE_SDK_API +#endif + +#ifdef ZTS +#include "TSRM.h" +#endif + +/* + Declare any global variables you may need between the BEGIN + and END macros here: + +ZEND_BEGIN_MODULE_GLOBALS(wxwork_finance_sdk) + zend_long global_value; + char *global_string; +ZEND_END_MODULE_GLOBALS(wxwork_finance_sdk) +*/ + +/* Always refer to the globals in your function as WXWORK_FINANCE_SDK_G(variable). + You are encouraged to rename these macros something shorter, see + examples in any other php module directory. +*/ +#define WXWORK_FINANCE_SDK_G(v) ZEND_MODULE_GLOBALS_ACCESSOR(wxwork_finance_sdk, v) + +#if defined(ZTS) && defined(COMPILE_DL_WXWORK_FINANCE_SDK) +ZEND_TSRMLS_CACHE_EXTERN() +#endif + +#include "zend_exceptions.h" +#include "ext/spl/spl_exceptions.h" +#include "WeWorkFinanceSdk_C.h" + +#define TRACE(fmt, ...) do { trace(__FILE__, __LINE__, __FUNCTION__, fmt, ##__VA_ARGS__); } while (0) + +static inline void trace(const char *file, int line, const char* function, const char *fmt, ...) { + fprintf(stderr, "%s(%s:%d) - ", function, file, line); + va_list args; + va_start(args, fmt); + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n"); + va_end(args); +} + +#endif /* PHP_WXWORK_FINANCE_SDK_H */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/sync.sh b/sync.sh new file mode 100755 index 0000000..aaf1aa3 --- /dev/null +++ b/sync.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +scp -r ../php-wxwork-finance-sdk pangxl@dev.lanyicj.cn:~/wechat_sdk diff --git a/wxwork_finance_sdk.c b/wxwork_finance_sdk.c new file mode 100644 index 0000000..4589de8 --- /dev/null +++ b/wxwork_finance_sdk.c @@ -0,0 +1,259 @@ +/* + +----------------------------------------------------------------------+ + | PHP Version 7 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2018 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "php.h" +#include "php_ini.h" +#include "ext/standard/info.h" +#include "php_wxwork_finance_sdk.h" + +/* If you declare any globals in php_wxwork_finance_sdk.h uncomment this: +ZEND_DECLARE_MODULE_GLOBALS(wxwork_finance_sdk) +*/ + +/* True global resources - no need for thread safety here */ +static int le_wxwork_finance_sdk; +const static char *VERSION = "1.0"; + +static WeWorkFinanceSdk_t *sdk; + +static zend_class_entry *wxwork_finance_sdk_ce; +static zend_class_entry *wxwork_finance_sdk_exception_ce; + + +/** +* options = [ + 'proxy_host' => 'http://www.baidu.com', + 'proxy_password' => 'helloworld' + ] +*/ +PHP_METHOD(WxworkFinanceSdk, __construct) +{ + zend_string *corp_id, *secret; + zval *option_zval; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS|a", &corp_id, &secret, &option_zval) == FAILURE) { + return; + } + + if (ZSTR_LEN(corp_id) == 0 || ZSTR_LEN(secret) == 0) { + zend_throw_exception(spl_ce_InvalidArgumentException, "corpId and secret cannot be bull", 0); + } + + TRACE("copr_id value=%s", ZSTR_VAL(corp_id)); + + + zval *this = getThis(); + zend_class_entry *ce = Z_OBJCE_P(this); + + zend_declare_property_string(ce, "_corpId", sizeof("_corpId") - 1, ZSTR_VAL(corp_id), ZEND_ACC_PRIVATE); + zend_declare_property_string(ce, "_secret", sizeof("_secret") - 1, ZSTR_VAL(secret), ZEND_ACC_PRIVATE); + + if (option_zval) { + zval *r = zend_hash_find(Z_ARR_P(option_zval), zend_string_init("proxy_host", sizeof("proxy_host") - 1, 0)); + TRACE("proxy_host value=%s", Z_STRVAL_P(r)); + } + +} + + +static const zend_function_entry wxwork_finance_sdk_class_methods[] = { + PHP_ME(WxworkFinanceSdk, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR) + PHP_FE_END +}; + +static const zend_function_entry wxwork_finance_sdk_exception_methods[] = { + PHP_FE_END +}; + + +/* {{{ PHP_INI + */ +/* Remove comments and fill if you need to have entries in php.ini +PHP_INI_BEGIN() + STD_PHP_INI_ENTRY("wxwork_finance_sdk.global_value", "42", PHP_INI_ALL, OnUpdateLong, global_value, zend_wxwork_finance_sdk_globals, wxwork_finance_sdk_globals) + STD_PHP_INI_ENTRY("wxwork_finance_sdk.global_string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_wxwork_finance_sdk_globals, wxwork_finance_sdk_globals) +PHP_INI_END() +*/ +/* }}} */ + +/* Remove the following function when you have successfully modified config.m4 + so that your module can be compiled into PHP, it exists only for testing + purposes. */ + +/* Every user-visible function in PHP should document itself in the source */ +/* {{{ proto string confirm_wxwork_finance_sdk_compiled(string arg) + Return a string to confirm that the module is compiled in */ +PHP_FUNCTION(confirm_wxwork_finance_sdk_compiled) +{ + char *arg = NULL; + size_t arg_len, len; + zend_string *strg; + + if (zend_parse_parameters(ZEND_NUM_ARGS(), "s", &arg, &arg_len) == FAILURE) { + return; + } + + strg = strpprintf(0, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "wxwork_finance_sdk", arg); + + RETURN_STR(strg); +} + +/* }}} */ +/* The previous line is meant for vim and emacs, so it can correctly fold and + unfold functions in source code. See the corresponding marks just before + function definition, where the functions purpose is also documented. Please + follow this convention for the convenience of others editing your code. +*/ + + +/* {{{ php_wxwork_finance_sdk_init_globals + */ +/* Uncomment this function if you have INI entries +static void php_wxwork_finance_sdk_init_globals(zend_wxwork_finance_sdk_globals *wxwork_finance_sdk_globals) +{ + wxwork_finance_sdk_globals->global_value = 0; + wxwork_finance_sdk_globals->global_string = NULL; +} +*/ +/* }}} */ + +/* {{{ PHP_MINIT_FUNCTION + */ +PHP_MINIT_FUNCTION(wxwork_finance_sdk) +{ + /* If you have INI entries, uncomment these lines + REGISTER_INI_ENTRIES(); + */ + + // define WxworkFinanceSdkException + zend_class_entry wxwork_finance_sdk_exception_def; + INIT_CLASS_ENTRY(wxwork_finance_sdk_exception_def, "WxworkFinanceSdkException", wxwork_finance_sdk_exception_methods); + wxwork_finance_sdk_exception_ce = zend_register_internal_class_ex(&wxwork_finance_sdk_exception_def, zend_ce_exception); + + zend_class_entry wxwork_finance_sdk_def; + INIT_CLASS_ENTRY(wxwork_finance_sdk_def, "WxworkFinanceSdk", wxwork_finance_sdk_class_methods); + wxwork_finance_sdk_ce = zend_register_internal_class(&wxwork_finance_sdk_def); + + zend_declare_property_string(wxwork_finance_sdk_ce, "_corpId", sizeof("_corpId") - 1, "", ZEND_ACC_PRIVATE); + zend_declare_property_string(wxwork_finance_sdk_ce, "_secret", sizeof("_secret") - 1, "", ZEND_ACC_PRIVATE); + zend_declare_property_string(wxwork_finance_sdk_ce, "_proxy_host", sizeof("_proxy_host") - 1, "", ZEND_ACC_PRIVATE); + zend_declare_property_string(wxwork_finance_sdk_ce, "_proxy_password", sizeof("_proxy_password") - 1, "", ZEND_ACC_PRIVATE); + + + zend_declare_class_constant_string(wxwork_finance_sdk_ce, "VERSION", sizeof("VERSION") - 1, VERSION); + + + return SUCCESS; +} +/* }}} */ + +/* {{{ PHP_MSHUTDOWN_FUNCTION + */ +PHP_MSHUTDOWN_FUNCTION(wxwork_finance_sdk) +{ + /* uncomment this line if you have INI entries + UNREGISTER_INI_ENTRIES(); + */ + return SUCCESS; +} +/* }}} */ + +/* Remove if there's nothing to do at request start */ +/* {{{ PHP_RINIT_FUNCTION + */ +PHP_RINIT_FUNCTION(wxwork_finance_sdk) +{ +#if defined(COMPILE_DL_WXWORK_FINANCE_SDK) && defined(ZTS) + ZEND_TSRMLS_CACHE_UPDATE(); +#endif + return SUCCESS; +} +/* }}} */ + +/* Remove if there's nothing to do at request end */ +/* {{{ PHP_RSHUTDOWN_FUNCTION + */ +PHP_RSHUTDOWN_FUNCTION(wxwork_finance_sdk) +{ + return SUCCESS; +} +/* }}} */ + +/* {{{ PHP_MINFO_FUNCTION + */ +PHP_MINFO_FUNCTION(wxwork_finance_sdk) +{ + php_info_print_table_start(); + php_info_print_table_header(2, "wxwork_finance_sdk support", "enabled"); + php_info_print_table_end(); + + /* Remove comments if you have entries in php.ini + DISPLAY_INI_ENTRIES(); + */ +} +/* }}} */ + + + +/* {{{ wxwork_finance_sdk_functions[] + * + * Every user visible function must have an entry in wxwork_finance_sdk_functions[]. + */ +const zend_function_entry wxwork_finance_sdk_functions[] = { + PHP_FE(confirm_wxwork_finance_sdk_compiled, NULL) /* For testing, remove later. */ + PHP_FE_END /* Must be the last line in wxwork_finance_sdk_functions[] */ +}; +/* }}} */ + +/* {{{ wxwork_finance_sdk_module_entry + */ +zend_module_entry wxwork_finance_sdk_module_entry = { + STANDARD_MODULE_HEADER, + "wxwork_finance_sdk", + wxwork_finance_sdk_functions, + PHP_MINIT(wxwork_finance_sdk), + PHP_MSHUTDOWN(wxwork_finance_sdk), + PHP_RINIT(wxwork_finance_sdk), /* Replace with NULL if there's nothing to do at request start */ + PHP_RSHUTDOWN(wxwork_finance_sdk), /* Replace with NULL if there's nothing to do at request end */ + PHP_MINFO(wxwork_finance_sdk), + PHP_WXWORK_FINANCE_SDK_VERSION, + STANDARD_MODULE_PROPERTIES +}; +/* }}} */ + +#ifdef COMPILE_DL_WXWORK_FINANCE_SDK +#ifdef ZTS +ZEND_TSRMLS_CACHE_DEFINE() +#endif +ZEND_GET_MODULE(wxwork_finance_sdk) +#endif + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: noet sw=4 ts=4 fdm=marker + * vim<600: noet sw=4 ts=4 + */ diff --git a/wxwork_finance_sdk.php b/wxwork_finance_sdk.php new file mode 100644 index 0000000..d3e4b94 --- /dev/null +++ b/wxwork_finance_sdk.php @@ -0,0 +1,9 @@ + "hello", + "proxy_password" => "world" +]); +var_dump($obj); \ No newline at end of file