Compare commits

...

59 Commits

Author SHA1 Message Date
933bfbcfef Merge branch 'master' of http://nas.jz7.cn:3001/cf_cloud/wx-finance-sdk 2025-09-17 16:33:10 +08:00
John
34f12c8a33
Update README.md 2023-12-13 19:22:15 -06:00
John
c537d7a4db
支持 Php8 2023-12-13 19:21:38 -06:00
John
66d86c5058
Merge pull request #46 from singee77/php8
feat: 支持PHP8
2023-12-13 19:19:59 -06:00
Singee77
9d48ce9f07 feat: 支持PHP8 2023-12-07 10:09:31 +08:00
pangdahua
e3bcca6415 chore: 更友好的错误信息 2023-11-07 17:57:21 +08:00
pangdahua
140fb486f6 chore: 更新示例 2023-11-07 10:35:30 +08:00
pangdahua
9d13324545 chore: release 2023-11-07 10:29:00 +08:00
pangdahua
ffabfd41ea chore: 防止多次释放 2023-11-07 09:33:18 +08:00
庞大花
7771b8341c
Update README.md 2022-05-13 10:00:25 +08:00
庞大花
a5de3fa43a
Update README.md 2022-05-13 09:53:09 +08:00
庞大花
0c5291c1b7
Update README.md 2022-03-14 12:14:05 +08:00
庞大花
2358cd9ed5
Update README.md 2022-01-28 11:28:05 +08:00
庞大花
96af01dc68
Update README.md 2021-10-08 19:08:16 +08:00
庞大花
8be0ff8a97
Update README.md 2021-08-06 09:25:23 +08:00
庞大花
0b249f3748
Update README.md 2021-08-06 09:24:47 +08:00
庞大花
9b1c5e77e6
Update README.md 2020-12-29 18:13:18 +08:00
庞大花
7207840314
Update README.md
新增getMediaData 实现可以直接对接三方存储平台
2020-12-29 09:29:29 +08:00
庞大花
e07f95b4e4
Merge pull request #27 from zhanzhaopeng1/master
新增getMediaData方法
2020-12-29 09:08:50 +08:00
zhaopeng053
51ed0b64ca fix bug 2020-12-28 18:04:38 +08:00
zhaopeng053
d14cc52908 fix bug 2020-12-28 18:01:30 +08:00
zhaopeng053
8d46b53462 merge upstream master 2020-12-28 17:57:00 +08:00
zhaopeng053
f801fcc78a format code 2020-12-28 17:35:46 +08:00
zhaopeng053
41a43dfe34 update return 2020-12-24 18:11:27 +08:00
zhaopeng053
f896e067bf update return 2020-12-24 15:57:28 +08:00
zhaopeng053
dc027fb324 新增getMediaData方法 2020-12-24 15:30:13 +08:00
庞大花
e0622a0b35
Update README.md 2020-12-10 09:38:11 +08:00
庞大花
817a8fe4ce
Update wxwork_finance_sdk.php 2020-11-27 17:02:12 +08:00
pangdahua
fe8171cfd0 Merge branch 'master' of github.com:pangdahua/php7-wxwork-finance-sdk 2020-10-11 11:05:52 +08:00
pangdahua
bedd9f1d8a feta: 定义默认超时时间 2020-10-11 11:05:19 +08:00
庞大花
e31bddb23d
Update README.md 2020-10-10 20:27:41 +08:00
庞大花
5ebc39762d
Merge pull request #15 from pangdahua/hotfix/issue_14
Hotfix/issue 14
2020-10-10 20:05:51 +08:00
pangdahua
cef9717212 fix: 多企业下错误 2020-10-10 20:02:53 +08:00
pangdahua
4e7b385439 fix: 多企业下错误 2020-10-10 18:59:52 +08:00
pangdahua
e981e07d85 fix: 多企业下错误 2020-10-10 18:20:57 +08:00
pangdahua
e4b2bdbcc2 fix: 多企业下错误 2020-10-10 18:17:58 +08:00
PHP-庞小龙
7f9354782c fix: 多企业下错误 2020-10-10 18:14:14 +08:00
庞大花
d08c0c3e55
Update README.md 2020-07-24 15:14:09 +08:00
庞大花
d6cef37802
Update wxwork_finance_sdk.c
fix 资源释放
2020-07-09 12:59:39 +08:00
庞大花
6fd962b58d
Delete build.sh 2020-06-14 18:23:10 +08:00
pangdahua
02d3fbb561 Merge branch 'master' of github.com:pangdahua/php7-wxwork-finance-sdk 2020-06-01 17:10:15 +08:00
pangdahua
f2625b99f2 fix: 修复段错误, 修复代理不生效 2020-06-01 17:09:59 +08:00
庞大花
6230dce92e
Update README.md 2020-03-18 14:04:22 +08:00
pangdahua
cc26d5bff3 feta: 完善demo 2020-03-10 16:12:23 +08:00
pangdahua
ff395f5338 feat: downloadMedia 替换 getMediadata 2020-03-10 16:11:42 +08:00
pangdahua
058675e81c Merge branch 'master' of github.com:pangdahua/php7-wxwork-finance-sdk 2020-03-09 18:24:23 +08:00
pangdahua
5048b5daac fix: 数据类型错误 2020-03-09 18:23:59 +08:00
庞大花
d5e0a1225f
Update README.md 2020-03-09 10:37:20 +08:00
庞大花
3ffa66bbc9
Update README.md 2020-03-09 10:36:19 +08:00
庞大花
40ff9778b5
删除无用文件 2020-03-09 10:32:53 +08:00
pangdahua
88ba48a324 feat(增加decryptData方法): decryptData 实现对数据的解密。完善demo 2020-03-09 10:31:34 +08:00
pangdahua
3100c27f6e fix: config.m4 add libpath error 2020-03-06 16:45:23 +08:00
庞大花
331e20ad2e
Update README.md 2020-03-02 09:16:01 +08:00
庞大花
b9c7603c36
Update README.md 2020-02-29 13:31:41 +08:00
庞大花
6e9af70b06
Update README.md 2020-02-29 13:30:18 +08:00
pangdahua
1970aed910 feta: 增加获取媒体内容 2020-02-29 13:26:54 +08:00
pangdahua
e16af1ec19 feta: 实现GetChatData 2020-02-27 20:10:41 +08:00
PHP-庞小龙
f40dff7324 feat: init 2020-02-25 18:49:01 +08:00
庞大花
8d8aeae2c1
Initial commit 2020-02-20 21:25:49 +08:00
10 changed files with 1017 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
sync.sh
build.sh
.idea/

1
CREDITS Normal file
View File

@ -0,0 +1 @@
wxwork_finance_sdk

0
EXPERIMENTAL Normal file
View File

201
LICENSE Normal file
View File

@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

View File

@ -0,0 +1,93 @@
# wxwork_finance_sdk_wrapper
企业微信-会话内容存档PHP扩展
## 依赖
企业微信提供的sdk;
PHP VERSION >= 7.0
* 已支持 php8 感谢 @singee77 pr
openssl扩展
## 安装步骤及要求
```
$INSATLL_PHP_PATH/bin/phpize
./configure --with-php-config=$INSTALL_PHP_PATH/php-config --with-wxwork-finance-sdk=$WXWORK_FINANCE_C_SDK_PATH
make && make install
```
php.ini 增加 extension=wxwork_finance_sdk.so
## API
```php
WxworkFinanceSdkExcption::__construct();
```
```php
WxworkFinanceSdk::__construct(string $corpId, string $secret, array $options);
string $corpId 企业号
string $secret 秘钥
array $options = [ // 可选参数
'proxy_host' => string,
'proxy_password' => string,
'timeout' => 10, // 默认超时时间为10s
]
```
```php
string WxworkFinanceSdk::getChatData(int $seq, int $limit);
* 拉取聊天数据
$seq 起始位置
$limit 获取条数
```
```php
bool WxworkFinanceSdk::downloadMedia(string $sdkfileid, string $saveTo)
* 下载资源
$sdkfileid 资源id。来自chat 中的数据sdkfileid
$saveTo 本地保存的路径
```
```php
array WxworkFinanceSdk::getMediaData(string $sdkfileid, string $indexBuf='');
* 拉取静态资源数据,用于可以支持追加模式的三方存储平台
返回的数据结构体
$ret = [
'data' => '' // string 返回的数据
'nextIndex' => 'ddd' // string 获取下一段数据的句柄
'isFinished' => int // 1 数据已拉取完毕
];
```
* 感谢 @zhanzhaopeng1 PR
```php
string WxworkFinanceSdk::decryptData(string $randomKey, string $encryptStr);
* 解密数据
$randomKey 通过openssl解密后的key
$encryptStr chats 的加密数据
```
## 已知问题
1. free(): invalid pointer
* 定位intl扩展的冲突问题. php -m |grep intl 建议重新编译php 取消intl扩展
2. 与swoole的扩展冲突
* 优先加载wxwork_finance_sdk.so 后加载swoole 【@tisswb
## 示例
wxwork_finance_sdk.php
Alipay
<img src="https://github.com/pangdahua/php7-wxwork-finance-sdk/blob/sponsor/imgs/Alipay.png" width="230" height="230" />

92
config.m4 Normal file
View File

@ -0,0 +1,92 @@
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, $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)
PHP_SUBST(WXWORK_FINANCE_SDK_SHARED_LIBADD)
fi

13
config.w32 Normal file
View File

@ -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");
}

90
php_wxwork_finance_sdk.h Normal file
View File

@ -0,0 +1,90 @@
/*
+----------------------------------------------------------------------+
| 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);
}
#define WXWORK_SDK_G_NAME "_wecomSDK"
#define WXWORK_SDK_G_NAME_SIZE sizeof(WXWORK_SDK_G_NAME) - 1
// 默认超时时间
#define WXWORK_SDK_DEFAULT_TIMEOUT 30
#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
*/

474
wxwork_finance_sdk.c Normal file
View File

@ -0,0 +1,474 @@
/*
+----------------------------------------------------------------------+
| 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"
#include <errno.h>
/* If you declare any globals in php_wxwork_finance_sdk.h uncomment this:
ZEND_DECLARE_MODULE_GLOBALS(wxwork_finance_sdk)
*/
/** {{{ ARG_INFO
*/
ZEND_BEGIN_ARG_INFO_EX(wxwork_void_arginfo, 0, 0, 0)
ZEND_END_ARG_INFO()
/* }}} */
/* True global resources - no need for thread safety here */
static int le_wxwork_finance_sdk;
static zend_class_entry *wxwork_finance_sdk_ce;
static zend_class_entry *wxwork_finance_sdk_exception_ce;
/**
*
*/
static WeWorkFinanceSdk_t* wxwork_finance_internal_get_sdk(zval *wxwork_class_this)
{
zend_object *object = Z_OBJ_P(wxwork_class_this);
zval *wecom_sdk_zval = zend_read_property(object->ce, object, WXWORK_SDK_G_NAME, WXWORK_SDK_G_NAME_SIZE, 0, NULL);
WeWorkFinanceSdk_t *wecom_sdk = (WeWorkFinanceSdk_t *)Z_PTR_P(wecom_sdk_zval);
return wecom_sdk;
}
/**
options = [
'proxy_host' => 'http://www.baidu.com',
'proxy_password' => 'helloworld'
]
*/
PHP_METHOD(WxworkFinanceSdk, __construct)
{
char *corp_id, *secret;
size_t corp_id_len, secret_len;
zval *option_zval = NULL;
zval wecom_sdk_zval;
WeWorkFinanceSdk_t *wecom_sdk;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ss|a", &corp_id, &corp_id_len, &secret, &secret_len, &option_zval) == FAILURE) {
zend_error(E_ERROR, "param error");
return;
}
if (corp_id_len == 0 || secret_len == 0) {
zend_throw_exception(spl_ce_InvalidArgumentException, "corpId and secret cannot be bull", 0);
return;
}
zval *this = getThis();
zend_object *object = Z_OBJ_P(this);
// init wecom finance sdk
wecom_sdk = NewSdk();
int ret = Init(wecom_sdk, corp_id, secret);
if (ret != 0) {
zend_throw_exception(wxwork_finance_sdk_exception_ce, "Call WeWorkFinanceSdk_t Init error", ret);
return;
}
ZVAL_PTR(&wecom_sdk_zval, wecom_sdk);
zend_update_property(object->ce, object, WXWORK_SDK_G_NAME, WXWORK_SDK_G_NAME_SIZE, &wecom_sdk_zval);
zend_update_property_string(object->ce, object, "_corpId", sizeof("_corpId") - 1, corp_id);
zend_update_property_string(object->ce, object, "_secret", sizeof("_secret") - 1, secret);
if (option_zval) {
zval *proxy_host_zval = zend_hash_find(Z_ARR_P(option_zval), zend_string_init("proxy_host", sizeof("proxy_host") - 1, 0));
if (proxy_host_zval != NULL) {
zval *proxy_password_zval = zend_hash_find(Z_ARR_P(option_zval), zend_string_init("proxy_password", sizeof("proxy_password") - 1, 0));
zend_update_property_string(object->ce, object, "_proxy_host", sizeof("_proxy_host") - 1, Z_STRVAL_P(proxy_host_zval));
if (proxy_password_zval != NULL) {
zend_update_property_string(object->ce, object, "_proxy_password", sizeof("_proxy_password") - 1, Z_STRVAL_P(proxy_password_zval));
}
}
zval *timeout_zval = zend_hash_find(Z_ARR_P(option_zval), zend_string_init("timeout", sizeof("timeout") - 1, 0));
if (timeout_zval != NULL) {
zend_update_property_long(object->ce, object, "_timeout", sizeof("_timeout") - 1, zval_get_long(timeout_zval));
}
}
}
PHP_METHOD(WxworkFinanceSdk, __destruct)
{
zval *this = getThis();
WeWorkFinanceSdk_t *wecom_sdk = wxwork_finance_internal_get_sdk(this);
DestroySdk(wecom_sdk);
//TRACE("release wecom_sdk");
}
/**
{{{ proto public WxworkFinanceSdk::getChatData(int $seq, int $limit)
*/
PHP_METHOD(WxworkFinanceSdk, getChatData)
{
zend_long seq, limit = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll", &seq, &limit) == FAILURE) {
return;
}
Slice_t *chat_data = NewSlice();
if (NULL == chat_data) {
FreeSlice(chat_data);
zend_error(E_ERROR, "There is not enough memory!");
return;
}
zval *this = getThis();
zend_object *object = Z_OBJ_P(this);
WeWorkFinanceSdk_t *wecom_sdk = wxwork_finance_internal_get_sdk(this);
zval *proxy_host_zval = zend_read_property(object->ce, object, "_proxy_host", sizeof("_proxy_host") - 1, 0, NULL);
zval *proxy_password_zval = zend_read_property(object->ce, object, "_proxy_password", sizeof("_proxy_password") - 1, 0, NULL);
zval *timeout_zval = zend_read_property(object->ce, object, "_timeout", sizeof("_timeout") - 1, 0, NULL);
int ret = GetChatData(wecom_sdk, (int)seq, (int)limit, Z_STRVAL_P(proxy_host_zval), Z_STRVAL_P(proxy_password_zval), zval_get_long(timeout_zval), chat_data);
if (0 != ret) {
FreeSlice(chat_data);
zend_throw_exception(wxwork_finance_sdk_exception_ce, "Call WeWorkFinanceSdk_t GetChatData error", ret);
return;
}
zend_string *s = zend_string_init(GetContentFromSlice(chat_data), GetSliceLen(chat_data), 0);
RETURN_STR(s);
zval_ptr_dtor(proxy_host_zval);
zval_ptr_dtor(proxy_password_zval);
zval_ptr_dtor(timeout_zval);
FreeSlice(chat_data);
}
/* }}} */
/**
{{{ proto WxworkFinanceSdk->decryptData(string $encryptRandomKey, string $encryptData)
*/
PHP_METHOD(WxworkFinanceSdk, decryptData)
{
zend_string *encrypt_random_key, *encrypt_data;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &encrypt_random_key, &encrypt_data) == FAILURE) {
return;
}
Slice_t *msg = NewSlice();
int ret = DecryptData(ZSTR_VAL(encrypt_random_key), ZSTR_VAL(encrypt_data), msg);
if (ret != 0) {
zend_throw_exception(spl_ce_InvalidArgumentException, "DecryptData data error", ret);
return;
}
zend_string *return_msg = zend_string_init(GetContentFromSlice(msg), GetSliceLen(msg), 0);
RETURN_STR(return_msg);
FreeSlice(msg);
}
/**
{{{ proto WxworkFinanceSdk->downloadMedia(string $filedId, string $saveTo)
*/
PHP_METHOD(WxworkFinanceSdk, downloadMedia)
{
zend_string *sdk_filedid, *file_saveto;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &sdk_filedid, &file_saveto) == FAILURE) {
return;
}
zval *this = getThis();
zend_object *object = Z_OBJ_P(this);
zval *proxy_host_zval = zend_read_property(object->ce, object, "_proxy_host", sizeof("_proxy_host") - 1, 0, NULL);
zval *proxy_password_zval = zend_read_property(object->ce, object, "_proxy_password", sizeof("_proxy_password") - 1, 0, NULL);
zval *timeout_zval = zend_read_property(object->ce, object, "_timeout", sizeof("_timeout") - 1, 0, NULL);
FILE *fp = fopen(ZSTR_VAL(file_saveto), "wb");
if (NULL == fp) {
zend_throw_exception_ex(wxwork_finance_sdk_exception_ce, errno, "cannot write file: %s error %s", ZSTR_VAL(file_saveto), strerror(errno));
return;
}
MediaData_t *media_data = NewMediaData();
if (NULL == media_data) {
zend_error(E_ERROR, "There is not enough memory!");
return;
}
WeWorkFinanceSdk_t *wecom_sdk = wxwork_finance_internal_get_sdk(this);
do {
int ret = GetMediaData(wecom_sdk, GetOutIndexBuf(media_data), ZSTR_VAL(sdk_filedid), Z_STRVAL_P(proxy_host_zval), Z_STRVAL_P(proxy_password_zval), zval_get_long(timeout_zval), media_data);
if (0 != ret) {
FreeMediaData(media_data);
fclose(fp);
zend_throw_exception(wxwork_finance_sdk_exception_ce, "GetMediaData error", ret);
return;
}
fwrite(GetData(media_data), GetDataLen(media_data), 1, fp);
}while(IsMediaDataFinish(media_data) != 1);
fclose(fp);
FreeMediaData(media_data);
RETURN_TRUE;
}
PHP_METHOD(WxworkFinanceSdk, getMediaData)
{
zend_string *sdk_filedid, *index_buf;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "SS", &sdk_filedid, &index_buf) == FAILURE) {
return;
}
zval *this = getThis();
zend_object *object = Z_OBJ_P(this);
zval *proxy_host_zval = zend_read_property(object->ce, object, "_proxy_host", sizeof("_proxy_host") - 1, 0, NULL);
zval *proxy_password_zval = zend_read_property(object->ce, object, "_proxy_password", sizeof("_proxy_password") - 1, 0, NULL);
zval *timeout_zval = zend_read_property(object->ce, object, "_timeout", sizeof("_timeout") - 1, 0, NULL);
MediaData_t *media_data = NewMediaData();
if (NULL == media_data) {
zend_error(E_ERROR, "There is not enough memory!");
return;
}
WeWorkFinanceSdk_t *wecom_sdk = wxwork_finance_internal_get_sdk(this);
int ret = GetMediaData(wecom_sdk, ZSTR_VAL(index_buf), ZSTR_VAL(sdk_filedid), Z_STRVAL_P(proxy_host_zval), Z_STRVAL_P(proxy_password_zval), zval_get_long(timeout_zval), media_data);
if (0 != ret) {
zend_throw_exception(wxwork_finance_sdk_exception_ce, "GetMediaData error", ret);
return;
}
array_init(return_value);
add_assoc_stringl(return_value, "data", GetData(media_data), GetDataLen(media_data));
add_assoc_string(return_value, "nextIndex", GetOutIndexBuf(media_data));
add_assoc_bool(return_value, "isFinished", IsMediaDataFinish(media_data) == 1 ? 1 : 0);
//RETURN_STRINGL(GetData(media_data), GetDataLen(media_data));
FreeMediaData(media_data);
}
/* }}} */
static const zend_function_entry wxwork_finance_sdk_class_methods[] = {
PHP_ME(WxworkFinanceSdk, __construct, wxwork_void_arginfo, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
PHP_ME(WxworkFinanceSdk, getChatData, wxwork_void_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(WxworkFinanceSdk, decryptData, wxwork_void_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(WxworkFinanceSdk, downloadMedia, wxwork_void_arginfo, ZEND_ACC_PUBLIC)
PHP_ME(WxworkFinanceSdk, getMediaData, wxwork_void_arginfo, ZEND_ACC_PUBLIC)
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);
// http proxy
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);
// request timeout
zend_declare_property_long(wxwork_finance_sdk_ce, "_timeout", sizeof("_timeout") - 1, WXWORK_SDK_DEFAULT_TIMEOUT, ZEND_ACC_PRIVATE);
// declare wecom finance sdk
zend_declare_property_null(wxwork_finance_sdk_ce, WXWORK_SDK_G_NAME, WXWORK_SDK_G_NAME_SIZE, ZEND_ACC_PRIVATE);
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, wxwork_void_arginfo) /* 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
*/

50
wxwork_finance_sdk.php Normal file
View File

@ -0,0 +1,50 @@
<?php
gc_enable();
$startMemUsed = memory_get_usage();
function cal_mem()
{
global $startMemUsed;
echo "memory,", ceil((memory_get_usage() - $startMemUsed) / 1024), 'KB', PHP_EOL;
}
echo "start mypid=", getmypid(), PHP_EOL;
sleep(2);
$sdk = new WxworkFinanceSdk("1", "2");
$privateKey = <<<EOF
-----BEGIN RSA PRIVATE KEY-----
-----END RSA PRIVATE KEY-----
EOF;
$seq = 0;
$str = str_repeat('X', 1024 * 1024);
do{
echo "sync seq={$seq} ==>", cal_mem(), PHP_EOL;
gc_mem_caches();
gc_collect_cycles();
$wxChat = $sdk->getChatData($seq, 100);
$chats = json_decode($wxChat, true);
$chatRows = $chats['chatdata'];
foreach ($chatRows as $val) {
$decryptRandKey = null;
$decryptData = openssl_private_decrypt(base64_decode($val['encrypt_random_key']), $decryptRandKey, $privateKey, OPENSSL_PKCS1_PADDING);
$decryptChatRawContent = $sdk->decryptData($decryptRandKey, $val['encrypt_chat_msg']);
$j2 = json_decode($decryptChatRawContent, true);
$msgType = $j2['msgtype'];
if (in_array($msgType, ['image', 'video'])) {
try {
$sdk->downloadMedia($j2[$msgType]['sdkfileid'], "/tmp/download/{$j2[$msgType]['md5sum']}");
}catch(\Exception $e) {
var_dump($e);
var_dump($e->getMessage(), $e->getCode());
sleep(1);
}
}
unset($decryptRandKey);
}
echo "loop done ===>", cal_mem();
unset($chatRows, $wxChat, $chats);
gc_collect_cycles();gc_collect_cycles();
$seq = $val['seq'];
}while(true);
cal_mem();