merge upstream master
This commit is contained in:
commit
8d46b53462
16
README.md
16
README.md
@ -46,14 +46,28 @@ openssl扩展
|
||||
```
|
||||
|
||||
```php
|
||||
bool WxworkFinanceSdk::downloadMedia(string $fileId, string $savePath = '')
|
||||
bool WxworkFinanceSdk::downloadMedia(string $sdkfileid, string $saveTo)
|
||||
* 下载资源
|
||||
$sdkfileid 资源id。来自chat 中的数据sdkfileid
|
||||
$saveTo 本地保存的路径
|
||||
```
|
||||
|
||||
```php
|
||||
string WxworkFinanceSdk::decryptData(string $randomKey, string $encryptStr);
|
||||
* 解密数据
|
||||
$randomKey 通过openssl解密后的key
|
||||
$encryptStr chats 的加密数据
|
||||
```
|
||||
|
||||
## 问题
|
||||
1. free(): invalid pointer
|
||||
* 暂时定位intl扩展的冲突问题. php -m |grep intl 建议重新编译php 取消intl扩展
|
||||
|
||||
## 示例
|
||||
|
||||
wxwork_finance_sdk.php
|
||||
|
||||
打赏一下的话就更好了~
|
||||
Alipay
|
||||
|
||||
<img src="https://github.com/pangdahua/php7-wxwork-finance-sdk/blob/sponsor/imgs/Alipay.png" width="230" height="230" />
|
||||
|
||||
@ -73,6 +73,11 @@ static inline void trace(const char *file, int line, const char* function, const
|
||||
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 */
|
||||
|
||||
/*
|
||||
|
||||
@ -26,7 +26,6 @@
|
||||
#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)
|
||||
*/
|
||||
@ -37,10 +36,19 @@ 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 *sdk;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
static WeWorkFinanceSdk_t* wxwork_finance_internal_get_sdk(zval *wxwork_class_this)
|
||||
{
|
||||
zval *wecom_sdk_zval = zend_read_property(Z_OBJCE_P(wxwork_class_this), wxwork_class_this, 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 = [
|
||||
options = [
|
||||
'proxy_host' => 'http://www.baidu.com',
|
||||
'proxy_password' => 'helloworld'
|
||||
]
|
||||
@ -50,6 +58,8 @@ 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");
|
||||
@ -61,15 +71,19 @@ PHP_METHOD(WxworkFinanceSdk, __construct)
|
||||
return;
|
||||
}
|
||||
|
||||
int ret = Init(sdk, corp_id, secret);
|
||||
zval *this = getThis();
|
||||
zend_class_entry *ce = Z_OBJCE_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 *this = getThis();
|
||||
zend_class_entry *ce = Z_OBJCE_P(this);
|
||||
ZVAL_PTR(&wecom_sdk_zval, wecom_sdk);
|
||||
zend_update_property(ce, this, WXWORK_SDK_G_NAME, WXWORK_SDK_G_NAME_SIZE, &wecom_sdk_zval);
|
||||
|
||||
zend_update_property_string(ce, this, "_corpId", sizeof("_corpId") - 1, corp_id);
|
||||
zend_update_property_string(ce, this, "_secret", sizeof("_secret") - 1, secret);
|
||||
@ -92,6 +106,15 @@ PHP_METHOD(WxworkFinanceSdk, __construct)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
*/
|
||||
@ -114,10 +137,13 @@ PHP_METHOD(WxworkFinanceSdk, getChatData)
|
||||
zval *this = getThis();
|
||||
zend_class_entry *ce = Z_OBJCE_P(this);
|
||||
|
||||
WeWorkFinanceSdk_t *wecom_sdk = wxwork_finance_internal_get_sdk(this);
|
||||
|
||||
zval *proxy_host_zval = zend_read_property(ce, this, "_proxy_host", sizeof("_proxy_host") - 1, 0, NULL);
|
||||
zval *proxy_password_zval = zend_read_property(ce, this, "_proxy_password", sizeof("_proxy_password") - 1, 0, NULL);
|
||||
zval *timeout_zval = zend_read_property(ce, this, "_timeout", sizeof("_timeout") - 1, 0, NULL);
|
||||
int ret = GetChatData(sdk, (int)seq, (int)limit, Z_STRVAL_P(proxy_host_zval), Z_STRVAL_P(proxy_password_zval), zval_get_long(timeout_zval), chat_data);
|
||||
|
||||
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) {
|
||||
zend_throw_exception(wxwork_finance_sdk_exception_ce, "Call WeWorkFinanceSdk_t GetChatData error", ret);
|
||||
return;
|
||||
@ -161,7 +187,7 @@ PHP_METHOD(WxworkFinanceSdk, decryptData)
|
||||
}
|
||||
|
||||
/**
|
||||
{{{ proto WxworkFinanceSdk->getMediaData(string $filedId, string $index='')
|
||||
{{{ proto WxworkFinanceSdk->downloadMedia(string $filedId, string $saveTo)
|
||||
*/
|
||||
|
||||
PHP_METHOD(WxworkFinanceSdk, downloadMedia)
|
||||
@ -191,11 +217,14 @@ PHP_METHOD(WxworkFinanceSdk, downloadMedia)
|
||||
return;
|
||||
}
|
||||
|
||||
WeWorkFinanceSdk_t *wecom_sdk = wxwork_finance_internal_get_sdk(this);
|
||||
|
||||
do {
|
||||
int ret = GetMediaData(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);
|
||||
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;
|
||||
}
|
||||
@ -334,7 +363,9 @@ PHP_MINIT_FUNCTION(wxwork_finance_sdk)
|
||||
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, 10, ZEND_ACC_PRIVATE);
|
||||
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;
|
||||
}
|
||||
@ -361,8 +392,6 @@ PHP_RINIT_FUNCTION(wxwork_finance_sdk)
|
||||
ZEND_TSRMLS_CACHE_UPDATE();
|
||||
#endif
|
||||
|
||||
sdk = NewSdk();
|
||||
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
@ -372,7 +401,6 @@ PHP_RINIT_FUNCTION(wxwork_finance_sdk)
|
||||
*/
|
||||
PHP_RSHUTDOWN_FUNCTION(wxwork_finance_sdk)
|
||||
{
|
||||
DestroySdk(sdk);
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
@ -14,7 +14,7 @@ var_dump($chats);
|
||||
foreach ($chats['chatdata'] as $val) {
|
||||
$decryptRandKey = null;
|
||||
openssl_private_decrypt(base64_decode($val['encrypt_random_key']), $decryptRandKey, $privateKey, OPENSSL_PKCS1_PADDING);
|
||||
$obj->downloadMedia($sdkFileId, "/tmp/download");
|
||||
$obj->downloadMedia($sdkFileId, "/tmp/download/文件新名称.后缀");
|
||||
}
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user