feat(增加decryptData方法): decryptData 实现对数据的解密。完善demo
This commit is contained in:
parent
3100c27f6e
commit
88ba48a324
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1,3 @@
|
|||||||
sync.sh
|
sync.sh
|
||||||
|
build.sh
|
||||||
|
.idea/
|
||||||
|
|||||||
@ -140,6 +140,31 @@ PHP_METHOD(WxworkFinanceSdk, getChatData)
|
|||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
{{{ 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);
|
||||||
|
zend_string_release(return_msg);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
{{{ proto WxworkFinanceSdk->getMediaData(string $filedId, string $index='')
|
{{{ proto WxworkFinanceSdk->getMediaData(string $filedId, string $index='')
|
||||||
@ -187,6 +212,7 @@ static const zend_function_entry wxwork_finance_sdk_class_methods[] = {
|
|||||||
PHP_ME(WxworkFinanceSdk, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
|
PHP_ME(WxworkFinanceSdk, __construct, NULL, ZEND_ACC_PUBLIC|ZEND_ACC_CTOR)
|
||||||
PHP_ME(WxworkFinanceSdk, getChatData, NULL, ZEND_ACC_PUBLIC)
|
PHP_ME(WxworkFinanceSdk, getChatData, NULL, ZEND_ACC_PUBLIC)
|
||||||
PHP_ME(WxworkFinanceSdk, getMediaData, NULL, ZEND_ACC_PUBLIC)
|
PHP_ME(WxworkFinanceSdk, getMediaData, NULL, ZEND_ACC_PUBLIC)
|
||||||
|
PHP_ME(WxworkFinanceSdk, decryptData, NULL, ZEND_ACC_PUBLIC)
|
||||||
PHP_FE_END
|
PHP_FE_END
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -299,7 +325,7 @@ PHP_RINIT_FUNCTION(wxwork_finance_sdk)
|
|||||||
|
|
||||||
sdk = NewSdk();
|
sdk = NewSdk();
|
||||||
|
|
||||||
return SUCCESS;
|
return SUCCESS;
|
||||||
}
|
}
|
||||||
/* }}} */
|
/* }}} */
|
||||||
|
|
||||||
|
|||||||
@ -2,18 +2,26 @@
|
|||||||
|
|
||||||
echo "version=", WxworkFinanceSdk::VERSION, PHP_EOL;
|
echo "version=", WxworkFinanceSdk::VERSION, PHP_EOL;
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$obj = new WxworkFinanceSdk("wwd08coe7d775abaaa", "zJ6k0naVVQ--gt9PUSSEvs03zW_nlDVmjAkPOTAfrew", [
|
$obj = new WxworkFinanceSdk("wwd08coe7d775abaaa", "zJ6k0naVVQ--gt9PUSSEvs03zW_nlDVmjAkPOTAfrew", [
|
||||||
"proxy_host" => "hello",
|
"proxy_host" => "hello",
|
||||||
"proxy_password" => "world",
|
"proxy_password" => "world",
|
||||||
"timeout" => -2,
|
"timeout" => -2,
|
||||||
]);
|
]);
|
||||||
var_dump($obj);
|
// 私钥地址
|
||||||
|
$privateKey = file_get_contents('private.pem');
|
||||||
|
|
||||||
var_dump(json_decode($obj->getChatData(0, 100)));
|
$chats = json_decode($obj->getChatData(0, 100), true);
|
||||||
var_dump($obj->getMediaData("dddd"));
|
|
||||||
|
foreach ($chats['chatdata'] as $val) {
|
||||||
|
$decryptRandKey = null;
|
||||||
|
openssl_private_decrypt(base64_decode($val['encrypt_random_key']), $decryptRandKey, $privateKey, OPENSSL_PKCS1_PADDING);
|
||||||
|
$j = json_decode($obj->decryptData($decryptRandKey, $val['encrypt_chat_msg']));
|
||||||
|
var_dump($j);exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}catch(\Exception $e) {
|
}catch(\WxworkFinanceSdkException $e) {
|
||||||
var_dump($e->getMessage(), $e->getCode());
|
var_dump($e->getMessage(), $e->getCode());
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user