Skip to content
summershrimp edited this page Feb 27, 2015 · 5 revisions

#WeChat Interface gdanmaku-server provides a integrated wechat interface to help user easily integrate post danmaku function in their own wechat public platform. ##How to use it in your self-service gdanmaku-server edit settings.py or settings_local.py ,find a variable called WECHAT_TOKEN and set it to your token.

# WECHAT
WECHAT_TOKEN = "your token"

then log in your wechat public platform, set your wechat public account to develop mode in develop center, set server url to http://yourdomain:yourport/api/wechat , set Token same with WECHAT_TOKEN, then apply these settings.

wechat platform

now , you can use your own wechat public account as a poster.

##How to use gdanmaku-server wechat api with your own api you can use some keyword to mark a user to danmaku mode ,then POST all what wechat server to you to your self-service gdanmaku-server's wechat api. Make sure the token of your own service and the token of gdanmaku-server is the same . a small example:

<?php
header("Content-Type: text/html; charset=utf-8");
define ( 'TOKEN', 'HJOWQIJ' );
require_once './wx_class.php';
$wx = new WeChatHandler ( TOKEN );
function textHandler($request, $response) {
	$news = Array(Array(
			"Title"=>"大会注册",
			"Description"=>"点击这里填写注册抢票表格",
			"PicUrl"=>"http://XXX.sinaapp.com/qiang.png",
			"Url"=>"http://XXX.sinaapp.com/wx_signup.php?sec_wx_id=".$request->getFromUser()
			)
	);
	$str = $request->getContent();
	if(strpos($str,"大会注册") !== false)
		$response->news($news);
	else echo curl_post("http://gdanmaku.coding.io/api/wechat?".$_SERVER['QUERY_STRING'],$request->getRawPost());
}
$wx->setTextHandler ( "textHandler" );
$wx->Run ();


function curl_post($url, $data, $timeout = 3,$header = NULL, $cookie_jar = NULL, $cookie_file = NULL)
{
	$ch = curl_init();
	curl_setopt ($ch, CURLOPT_URL,$url);
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
	if($header != NULL)
		curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
	if($cookie_file != NULL)
		curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
	if($cookie_jar != NULL)
		curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_jar);
	$result = curl_exec ($ch);
	curl_close($ch);
	return $result;
}
?>
Clone this wiki locally