Gaoming13\WechatPhpSdk\Utils\SHA1::getSignature PHP Method

getSignature() static public method

获取微信消息的签名
static public getSignature ( string $token, string $timestamp, string $nonce ) : boolean | string
$token string 票据
$timestamp string 时间戳
$nonce string 随机字符串
return boolean | string
    static function getSignature($token, $timestamp, $nonce)
    {
        //排序
        try {
            $array = array($token, $timestamp, $nonce);
            sort($array, SORT_STRING);
            $str = implode($array);
            return sha1($str);
        } catch (\Exception $e) {
            @error_log('getSignature Error: ' . $e->getMessage(), 0);
            return FALSE;
        }
    }

Usage Example

	 		 * 	'type' => 'image',
	 		 *	'media_id' => 'Uq7OczuEGEyUu--dYjg7seTm-EJTa0Zj7UDP9zUGNkVpjcEHhl7tU2Mv8mFRiLKC'
			 * ));
			 * ```
    		 */
            case 'image':
                $xml = sprintf('<xml>
						<ToUserName><![CDATA[%s]]></ToUserName>
						<FromUserName><![CDATA[%s]]></FromUserName>
						<CreateTime>%s</CreateTime>
						<MsgType><![CDATA[image]]></MsgType>
						<Image>
						<MediaId><![CDATA[%s]]></MediaId>
						</Image>
						</xml>', $this->message->FromUserName, $this->message->ToUserName, time(), $msg['media_id']);