接着看看全网发布的测试用例怎么作:
一、模拟粉丝触发专用测试公众号的事件,并推送事件消息到专用测试公众号,第三方平台方开发者须要提取推送XML信息中的event值,并在5秒内当即返回按照下述要求组装的文本消息给粉丝;二、模拟粉丝发送文本消息给专用测试公众号,第三方平台方需根据文本消息的内容进行相应的响应;
三、模拟粉丝发送文本消息给专用测试公众号,第三方平台方需在5秒内返回空串代表暂时不回复,而后再当即使用客服消息接口发送消息回复粉丝。
代码以下:
$xmlTpl = "
%s
";
$keyword = isset ( $param ['Content'] ) ? trim ( $param ['Content'] ) : '';
if(isset($param ['Event']) && $param ['ToUserName'] == 'gh_3c884a361561'){ // 案例1
$contentStr = $param ['Event'] . 'from_callback';
}elseif ($keyword == "TESTCOMPONENT_MSG_TYPE_TEXT") { // 案例2
$contentStr = "TESTCOMPONENT_MSG_TYPE_TEXT_callback";
} elseif (strpos ( $keyword, "QUERY_AUTH_CODE:" ) !== false) { // 案例3
$ticket = str_replace ( "QUERY_AUTH_CODE:", "", $keyword );
$contentStr = $ticket . "_from_api";
$tokenInfo = WechatOpenApiLogic::getAuthorizerAccessTokenByAuthCode ( $ticket );
$param ['authorizerAccessToken'] = $tokenInfo ['authorization_info'] ['authorizer_access_token'];
self::sendServiceMsg ( $param ['FromUserName'], $param ['ToUserName'], 1, $contentStr ); // 客服消息接口
return 1;
}
$result = '';
if (! empty ( $contentStr )) {
$result = sprintf ( $xmlTpl, $param ['FromUserName'], $param ['ToUserName'], time (), $contentStr );
if (isset ( $_GET ['encrypt_type'] ) && $_GET ['encrypt_type'] == 'aes') { // 密文传输
$msgCryptObj = new WXBizMsgCrypt ( OPEN_MSG_VERIFY_TOKEN, OPEN_ENCRYPT_KEY, OPEN_APPID );
$encryptMsg = '';
$msgCryptObj->encryptMsg ( $result, $_GET ['timestamp'], $_GET ['nonce'], $encryptMsg );
$result = $encryptMsg;
}
}
全网发布接入检测: