本文整理匯總了PHP中Prpcrypt::encrypt方法的典型用法代碼示例。如果您正苦於以下問題:PHP Prpcrypt::encrypt方法的具體用法?PHP Prpcrypt::encrypt怎麽用?PHP Prpcrypt::encrypt使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Prpcrypt
的用法示例。
在下文中一共展示了Prpcrypt::encrypt方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: encryptMsg
/**
* 將公眾平台回複用戶的消息加密打包.
* <ol>
* <li>對要發送的消息進行AES-CBC加密</li>
* <li>生成安全簽名</li>
* <li>將消息密文和安全簽名打包成xml格式</li>
* </ol>
*
* @param $replyMsg string 公眾平台待回複用戶的消息,xml格式的字符串
* @param $timeStamp string 時間戳,可以自己生成,也可以用URL參數的timestamp
* @param $nonce string 隨機串,可以自己生成,也可以用URL參數的nonce
* @param &$encryptMsg string 加密後的可以直接回複用戶的密文,包括msg_signature, timestamp, nonce, encrypt的xml格式的字符串,
* 當return返回0時有效
*
* @return int 成功0,失敗返回對應的錯誤碼
*/
public function encryptMsg($replyMsg, $timeStamp, $nonce, &$encryptMsg)
{
$pc = new Prpcrypt($this->encodingAesKey);
//加密
$array = $pc->encrypt($replyMsg, $this->appId);
$ret = $array[0];
if ($ret != 0) {
return $ret;
}
if ($timeStamp == null) {
$timeStamp = time();
}
$encrypt = $array[1];
//生成安全簽名
$sha1 = new SHA1();
$array = $sha1->getSHA1($this->token, $timeStamp, $nonce, $encrypt);
$ret = $array[0];
if ($ret != 0) {
return $ret;
}
$signature = $array[1];
//生成發送的xml
$xmlparse = new XMLParse();
$encryptMsg = $xmlparse->generate($encrypt, $signature, $timeStamp, $nonce);
return ErrorCode::$OK;
}
示例2: encrypt
public function encrypt($replyMsg, $timeStamp, $nonce, &$encryptMsg)
{
$pc = new Prpcrypt($this->encodingAesKey);
$array = $pc->encrypt($replyMsg, $this->appId);
$ret = $array[0];
if ($ret != 0) {
return $ret;
}
if ($timeStamp == null) {
$timeStamp = time();
}
$encrypt = $array[1];
$sha1 = new SHA1;
$array = $sha1->getSHA1($this->token, $timeStamp, $nonce, $encrypt);
$ret = $array[0];
if ($ret != 0) {
return $ret;
}
$signature = $array[1];
$format = "<xml>
<Encrypt><![CDATA[%s]]></Encrypt>
<MsgSignature><![CDATA[%s]]></MsgSignature>
<TimeStamp>%s</TimeStamp>
<Nonce><![CDATA[%s]]></Nonce>
</xml>";
$encryptMsg = sprintf($format, $encrypt, $signature, $timeStamp, $nonce);
return ErrorCode::$OK;
}
示例3: EncryptMsg
public function EncryptMsg($plain, $timeStamp, $nonce, &$encryptMsg)
{
$pc = new Prpcrypt($this->m_encodingAesKey);
$array = $pc->encrypt($plain, $this->m_suiteKey);
$ret = $array[0];
if ($ret != 0) {
return $ret;
}
if ($timeStamp == null) {
$timeStamp = time();
}
$encrypt = $array[1];
$sha1 = new SHA1();
$array = $sha1->getSHA1($this->m_token, $timeStamp, $nonce, $encrypt);
$ret = $array[0];
if ($ret != 0) {
return $ret;
}
$signature = $array[1];
$encryptMsg = json_encode(array("msg_signature" => $signature, "encrypt" => $encrypt, "timeStamp" => $timeStamp, "nonce" => $nonce));
return ErrorCode::$OK;
}
示例4: reply
/**
*
* 回複微信服務器, 此函數支持鏈式操作
* Example: $this->text('msg tips')->reply();
* @param string $msg 要發送的信息, 默認取$this->_msg
* @param bool $return 是否返回信息而不拋出到瀏覽器 默認:否
*/
public function reply($msg = array(), $return = false)
{
if (empty($msg)) {
if (empty($this->_msg)) {
//防止不先設置回複內容,直接調用reply方法導致異常
return false;
}
$msg = $this->_msg;
}
$xmldata = $this->xml_encode($msg);
$this->log($xmldata);
if ($this->encrypt_type == 'aes') {
//如果來源消息為加密方式
$pc = new Prpcrypt($this->encodingAesKey);
$array = $pc->encrypt($xmldata, $this->appid);
$ret = $array[0];
if ($ret != 0) {
$this->log('encrypt err!');
return false;
}
$timestamp = time();
$nonce = rand(77, 999) * rand(605, 888) * rand(11, 99);
$encrypt = $array[1];
$tmpArr = array($this->token, $timestamp, $nonce, $encrypt);
//比普通公眾平台多了一個加密的密文
sort($tmpArr, SORT_STRING);
$signature = implode($tmpArr);
$signature = sha1($signature);
$xmldata = $this->generate($encrypt, $signature, $timestamp, $nonce);
$this->log($xmldata);
}
if ($return) {
return $xmldata;
} else {
echo $xmldata;
}
}
示例5: Prpcrypt
<?php
include_once "request.php";
$action = @get("action");
$source = @post("source");
$aesKey = @post("key");
$no = @post("no");
if (isset($source)) {
$pc = new Prpcrypt($aesKey);
if ($action == "encrypt") {
$result = $pc->encrypt($source, $no);
} else {
$result = $pc->decrypt($source);
// var_dump($result);
}
$response = array("success" => true, "result" => $result);
printf(json_encode($response));
}
/**
* PKCS7Encoder class
*
* 提供基於PKCS7算法的加解密接口.
*/
class PKCS7Encoder
{
public static $block_size = 32;
/**
* 對需要加密的明文進行填充補位
* @param $text 需要進行填充補位操作的明文
* @return 補齊明文字符串
*/