merge upstream master
This commit is contained in:
commit
8d46b53462
16
README.md
16
README.md
@ -46,14 +46,28 @@ openssl扩展
|
|||||||
```
|
```
|
||||||
|
|
||||||
```php
|
```php
|
||||||
bool WxworkFinanceSdk::downloadMedia(string $fileId, string $savePath = '')
|
bool WxworkFinanceSdk::downloadMedia(string $sdkfileid, string $saveTo)
|
||||||
|
* 下载资源
|
||||||
|
$sdkfileid 资源id。来自chat 中的数据sdkfileid
|
||||||
|
$saveTo 本地保存的路径
|
||||||
```
|
```
|
||||||
|
|
||||||
```php
|
```php
|
||||||
string WxworkFinanceSdk::decryptData(string $randomKey, string $encryptStr);
|
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
|
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);
|
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 */
|
#endif /* PHP_WXWORK_FINANCE_SDK_H */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -26,7 +26,6 @@
|
|||||||
#include "php_ini.h"
|
#include "php_ini.h"
|
||||||
#include "ext/standard/info.h"
|
#include "ext/standard/info.h"
|
||||||
#include "php_wxwork_finance_sdk.h"
|
#include "php_wxwork_finance_sdk.h"
|
||||||
|
|
||||||
/* If you declare any globals in php_wxwork_finance_sdk.h uncomment this:
|
/* If you declare any globals in php_wxwork_finance_sdk.h uncomment this:
|
||||||
ZEND_DECLARE_MODULE_GLOBALS(wxwork_finance_sdk)
|
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_ce;
|
||||||
static zend_class_entry *wxwork_finance_sdk_exception_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_host' => 'http://www.baidu.com',
|
||||||
'proxy_password' => 'helloworld'
|
'proxy_password' => 'helloworld'
|
||||||
]
|
]
|
||||||
@ -50,6 +58,8 @@ PHP_METHOD(WxworkFinanceSdk, __construct)
|
|||||||
char *corp_id, *secret;
|
char *corp_id, *secret;
|
||||||
size_t corp_id_len, secret_len;
|
size_t corp_id_len, secret_len;
|
||||||
zval *option_zval = NULL;
|
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) {
|
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");
|
zend_error(E_ERROR, "param error");
|
||||||
@ -61,15 +71,19 @@ PHP_METHOD(WxworkFinanceSdk, __construct)
|
|||||||
return;
|
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) {
|
if (ret != 0) {
|
||||||
zend_throw_exception(wxwork_finance_sdk_exception_ce, "Call WeWorkFinanceSdk_t Init error", ret);
|
zend_throw_exception(wxwork_finance_sdk_exception_ce, "Call WeWorkFinanceSdk_t Init error", ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
zval *this = getThis();
|
ZVAL_PTR(&wecom_sdk_zval, wecom_sdk);
|
||||||
zend_class_entry *ce = Z_OBJCE_P(this);
|
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, "_corpId", sizeof("_corpId") - 1, corp_id);
|
||||||
zend_update_property_string(ce, this, "_secret", sizeof("_secret") - 1, secret);
|
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)
|
{{{ proto public WxworkFinanceSdk::getChatData(int $seq, int $limit)
|
||||||
*/
|
*/
|
||||||
@ -114,10 +137,13 @@ PHP_METHOD(WxworkFinanceSdk, getChatData)
|
|||||||
zval *this = getThis();
|
zval *this = getThis();
|
||||||
zend_class_entry *ce = Z_OBJCE_P(this);
|
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_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 *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);
|
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) {
|
if (0 != ret) {
|
||||||
zend_throw_exception(wxwork_finance_sdk_exception_ce, "Call WeWorkFinanceSdk_t GetChatData error", ret);
|
zend_throw_exception(wxwork_finance_sdk_exception_ce, "Call WeWorkFinanceSdk_t GetChatData error", ret);
|
||||||
return;
|
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)
|
PHP_METHOD(WxworkFinanceSdk, downloadMedia)
|
||||||
@ -191,13 +217,16 @@ PHP_METHOD(WxworkFinanceSdk, downloadMedia)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WeWorkFinanceSdk_t *wecom_sdk = wxwork_finance_internal_get_sdk(this);
|
||||||
|
|
||||||
do {
|
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) {
|
if (0 != ret) {
|
||||||
FreeMediaData(media_data);
|
FreeMediaData(media_data);
|
||||||
zend_throw_exception(wxwork_finance_sdk_exception_ce, "GetMediaData error", ret);
|
fclose(fp);
|
||||||
return;
|
zend_throw_exception(wxwork_finance_sdk_exception_ce, "GetMediaData error", ret);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
fwrite(GetData(media_data), GetDataLen(media_data), 1, fp);
|
fwrite(GetData(media_data), GetDataLen(media_data), 1, fp);
|
||||||
}while(IsMediaDataFinish(media_data) != 1);
|
}while(IsMediaDataFinish(media_data) != 1);
|
||||||
@ -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_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_property_string(wxwork_finance_sdk_ce, "_proxy_password", sizeof("_proxy_password") - 1, "", ZEND_ACC_PRIVATE);
|
||||||
// request timeout
|
// 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;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
@ -361,8 +392,6 @@ PHP_RINIT_FUNCTION(wxwork_finance_sdk)
|
|||||||
ZEND_TSRMLS_CACHE_UPDATE();
|
ZEND_TSRMLS_CACHE_UPDATE();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
sdk = NewSdk();
|
|
||||||
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
@ -372,7 +401,6 @@ PHP_RINIT_FUNCTION(wxwork_finance_sdk)
|
|||||||
*/
|
*/
|
||||||
PHP_RSHUTDOWN_FUNCTION(wxwork_finance_sdk)
|
PHP_RSHUTDOWN_FUNCTION(wxwork_finance_sdk)
|
||||||
{
|
{
|
||||||
DestroySdk(sdk);
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|||||||
@ -14,7 +14,7 @@ var_dump($chats);
|
|||||||
foreach ($chats['chatdata'] as $val) {
|
foreach ($chats['chatdata'] as $val) {
|
||||||
$decryptRandKey = null;
|
$decryptRandKey = null;
|
||||||
openssl_private_decrypt(base64_decode($val['encrypt_random_key']), $decryptRandKey, $privateKey, OPENSSL_PKCS1_PADDING);
|
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