×i½u½ÓÁ˸oÏiÄ¿£¬ÆaÖÐÓÐÐeÇoÊÇҪʵÏÖÒ¡Ò»Ò¡ºi°u¹¦ÄÜ£¬ÔÚÍøÉÏËÑÁ˺þ㬶¼Ã»ÓÐÕÒµ½Ô´Âe£¬Ã»°i¨£¬Ö»ÓÐ×Ô¶¯Ð´ÁË£¬ÏÂÃaeС±a°ÑÎÒµÄÀͶ¯³É¹uÖÏi¸ø´o¼Ò¹(C)´o¼Ò²Î¿¼£¬±¾ÎÄдµÄ²»ºÃ£¬»¹Çe¸÷λ´oÏÀÌa³o±¦¹oÒa¼u£¬¹²Í¬Ñ§Ï°½ø²½¡£
*΢ÐŹٽ˵Ã÷ÈçÏÂ
**
Ò¡Ò»Ò¡ºi°u˵Ã÷
¹¦ÄÜ˵Ã÷
Ò¡Ò»Ò¡Öܱߺi°u½Ó¿ÚÊÇΪÏßÏÂÉÌ»§Ìa¹(C)µÄ¢ºi°u¹¦ÄÜ¡£Óû§¿ÉÒÔÔÚÉ̼ÒÃŵeµÈÏßϳ¡Ëuͨ¹ýÒ¡Ò»Ò¡ÖܱßÁiÈ¡É̼Ңŵĺi°u£¬ÔÚÏßÉÏת¢*ÖÏiÎÞЧ¡£
¿ª¢Õß¿Éͨ¹ý½Ó¿Ú¿ª¢Ò¡Ò»Ò¡ºi°u¹¦ÄÜ£¬Ìصa°uÀ¨£º
1.¿ÉÑ¡ÔñʹÓÃÄ£°a¼ÓÔØÒ³»o×Ô¶¨ÒaHtml5Ò³Ãaeµ÷Æð΢ÐÅÔÉuºi°uÒ³Ãae(Ïe¼u´´½¨ºi°u»i¶¯ÖÐuse_template×ֶΣ¬1ΪʹÓÃÄ£°a£¬2ΪʹÓÃ×Ô¶¨ÒaHtml5Ò³Ãae)
2.ÔÉuºi°uÒ³Ãae²ðºi°u£¬ÎÞÐeͨ¹ý¹«ÖÚºÅÏuϢϢ
3.Ìa¹(C)¹Ø×¢¹«ÖÚºÅÄÜÁ¦£¬Óû§¿É×ÔÐÐÑ¡ÔñÊÇñ¹Ø×¢(Áѱaºi°u*ÖÏiʱÎÞЧ)
4.Íe³ÉÒ³Ãae¿ÉÅaÖÃÌøתÁ´½Ó£¬¿ÉÌøתÉÌ»§µÄÆaËu×Ô¶¨ÒaHtml5Ò³Ãae
5.ͬһ¸oÓû§ÔÚµ¥¸oºi°u»i¶¯ÖÐÖ»ÄÜÁiÈ¡1´Îºi°u
Óû§²a½»»¥Á÷³Ì
ºi°u×e¼þ½Ó¿Úµ÷ÓÃÁ÷³Ì
1. ÉeÇeºi°u½Ó¿ÚȨÏÞ£ºµÇ¼ҡһҡÖܱßÉÌ»§ºǫhttps://zb.weixin.qq.com ,½øÈe¿ª¢ÕßÖ§³Ö£¬ÉeÇe¿ªÍ¨Ò¡Ò»Ò¡ºi°u×e¼þ½Ó¿Ú;
2. ºi°uԤϵ¥£ºµ÷ÓÃ΢ÐÅÖ§¸¶µÄapi½øÐкi°uԤϵ¥£¬¸aeÖªÐeÒª¢ÅµÄºi°u½ð¶i£¬ÈËÊý£¬Éu³Éºi°uticket£»
3. ´´½¨»i¶¯²¢Â¼Èeºi°uÐÅÏ¢£ºµ÷ÓÃÒ¡Öܱßƽ̨µÄapi¼Èe´´½¨ºi°u»i¶¯²¢Â¼ÈeÐÅÏ¢£¬´«ÈeԤϵ¥Ê±Éu³ÉµÄºi°uticket£»
4. µ÷ÓÃjsapi³eºi°u£ºÔÚÒ¡³oµÄÒ³ÃaeÖÐͨ¹ýµ÷ÓÃjsapi³eºi°u£¬³eÖкi°uµÄÓû§¿ÉÒÔ²ðºi°u£»
5. µ÷ÓÃÒÔÉϽӿÚʱ£¬ºi°uÌa¹(C)ÉÌ»§ºÍºi°u¢*ÅÉÌ»§¹«ÖÚºÅÒªÇoÒ»Ö¡£
˵Ã÷£º
ºi°uÌa¹(C)ÉÌ»§£ººi°uԤϵ¥½Ó¿Ú´«ÈeµÄ²ÎÊýwxappidËu´u±iµÄÉÌ»§
ºi°u¢ÅÉÌ»§£ºµ÷Óúi°u½Ó¿Ú´´½¨ºi°u»i¶¯¡¢Â¼Èeºi°uÐÅÏ¢¡¢¢Åºi°uµÄÉÌ»§¹«ÖÚºÅËuÒÔ²½ÖeÓ¦¸ÃÊÇ ¢Ù ´´½¨ºi°u»i¶¯ ¢Ú Ԥϵ¥ ¢Û ¼Èeºi°uÕÒ³oÀ´ÁË֮ǰÕuÀiµÄÀa ÔÚдһÏÂ1.´´½¨»i¶¯
½Ó¿Ú˵Ã÷
´´½¨ºi°u»i¶¯£¬ÉeÖúi°u»i¶¯ÓÐЧÆÚ£¬ºi°u»i¶¯¿ª¹ØµÈ»u±¾ÐÅÏ¢£¬*µ»Ø»i¶¯id
½Ó¿Úµ÷ÓÃ˵Ã÷
* þÎñÆ÷¶Ëµ÷ÓÃ**
httpÇeÇo*½Ê½: POST
URL: https://api.weixin.qq.com/shakearound/lottery/addlotteryinfo?access_token=ACCESSTOKEN&use;_template=1&logo;_url=LOGO_URL
ÇeÇo²ÎÊý˵Ã÷
ÇeÇoʾÀý
Content-Type: application/json Post Body:
{
"title": "title",
"desc": "desc",
"onoff": 1,
"begin_time": 1428854400,
"expire_time": 1428940800,
"sponsor_appid": "wxxxxxxxxxxxxxx",
"total": 10,
"jump_url": JUMP_URL,
"key": "keyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
}
*µ»ØÊý¾Ý˵Ã÷
ʾÀý
{
"errcode":0,
"errmsg":"",
"lottery_id":"xxxxxxllllll",
"page_id":1,
}
/**
* Ò¡Ò»Ò¡ºi°u ´´½¨»i¶¯
* @author jiosen
*/
class addlotteryinfo_pub extends Wxpay_client_pub
{
var $code;//codeÂe£¬ÓÃÒÔ»ñÈ¡openid
var $openid;//Óû§µÄopenid
function __construct($access_token,$logo)
{
//ÉeÖýӿÚÁ´½Ó
$this->url = "https://api.weixin.qq.com/shakearound/lottery/addlotteryinfo?access_token=".$access_token."&use;_template=1&logo;_url=".$logo;
//ÉeÖÃcurl³¬Ê±Ê±¼a
$this->curl_timeout = WxPayConf_pub::CURL_TIMEOUT;
}
/**
* Éu³É½Ó¿Ú²ÎÊý json
*/
function createJson()
{
try
{
//¼i²a±ØÌi²ÎÊý
if($this->parameters["title"] == null)
{
throw new SDKRuntimeException("ȱÉÙ³e½±»i¶¯Ãu³Ætitle£¡"."<br>");
}elseif ($this->parameters["desc"] == null ) {
throw new SDKRuntimeException("ȱÉÙ³e½±»i¶¯ÃeÊodesc£¡"."<br>");
}elseif ($this->parameters["begin_time"] == null) {
throw new SDKRuntimeException("ȱÉÙ»i¶¯¿ªÊ¼Ê±¼a begin_time£¡"."<br>");
}elseif ($this->parameters["expire_time"] == null) {
throw new SDKRuntimeException("ȱÉÙ»i¶¯½aÊøʱ¼a expire_time£¡"."<br>");
}elseif ($this->parameters["total"] == null) {
throw new SDKRuntimeException("ȱÉÙºi°u×ÜÊýtotal£¡"."<br>");
}elseif ($this->parameters["jump_url"] == null) {
throw new SDKRuntimeException("ȱÉÙºi°u¹Ø×¢ÌøתÁ¬½Ójump_url£¡"."<br>");
}elseif ($this->parameters["key"] == null) {
throw new SDKRuntimeException("ȱÉÙºi°ukey£¡"."<br>");
}
$this->parameters["title"] = urlencode($this->parameters["title"]);
$this->parameters["desc"] = urlencode($this->parameters["desc"]);
$this->parameters["onoff"] = '1';//¿ªÆo»i¶¯
$this->parameters["sponsor_appid"] = WxPayConf_pub::APPID;//¹«ÖÚÕ˺ÅID
//var_dump($this->parameters);
//echo json_encode($this->parameters);
return json_encode($this->parameters);
}catch (SDKRuntimeException $e)
{
die($e->errorMessage());
}
}
function hbpreorder()
{
$data = $this->createJson();
$result = $this->curl_post($this->url,urldecode($data));
$result = json_decode($result);
return $result;
}
function curl_post($url,$data)
{
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, 1);//*¢ËÍÒ»¸o³£¹aeµÄPostÇeÇo
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);//PostÌa½»µÄÊý¾Ý°u
$rv = curl_exec($curl);//Êa³oÄÚÈÝ
curl_close($curl);
return $rv;
}
/**
* ×÷ÓãºÉu³É¿ÉÒÔ»ñµÃcodeµÄurl
*/
function createOauthUrlForCode($redirectUrl)
{
$urlObj["appid"] = WxPayConf_pub::APPID;
$urlObj["redirect_uri"] = "$redirectUrl";
$urlObj["response_type"] = "code";
$urlObj["scope"] = "snsapi_base";
$urlObj["state"] = "STATE"."#wechat_redirect";
$bizString = $this->formatBizQueryParaMap($urlObj, false);
return "https://open.weixin.qq.com/connect/oauth2/authorize?".$bizString;
}
/**
* ×÷ÓãºÉu³É¿ÉÒÔ»ñµÃopenidµÄurl
*/
function createOauthUrlForOpenid()
{
$urlObj["appid"] = WxPayConf_pub::APPID;
$urlObj["secret"] = WxPayConf_pub::APPSECRET;
$urlObj["code"] = $this->code;
$urlObj["grant_type"] = "authorization_code";
$bizString = $this->formatBizQueryParaMap($urlObj, false);
return "https://api.weixin.qq.com/sns/oauth2/access_token?".$bizString;
}
/**
* ×÷ÓãºÍ¨¹ýcurlÏo΢ÐÅÌa½»code£¬ÒÔ»ñÈ¡openid
*/
function getOpenid()
{
$url = $this->createOauthUrlForOpenid();
//³oʼ»¯curl
$ch = curl_init();
//ÉeÖó¬Ê±
curl_setopt($ch, CURLOP_TIMEOUT, $this->curl_timeout);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
//ÔËÐÐcurl£¬½a¹uÒÔjasonÐÎʽ*µ»Ø
$res = curl_exec($ch);
curl_close($ch);
$data = json_decode($res,true);
$this->openid = $data['openid'];
return $this->openid;
}
/**
* ×÷ÓãºÉeÖÃcode
*/
function setCode($code_)
{
$this->code = $code_;
}
}
ҪעÒaÌa½»µÄÊý¾ÝÊÇjson ²»ÊÇxml
Ç°¶ËÒ³ÃaeËae±a×oÒ»ÏÂ
php ´uÂe
$title = $_POST['title'];
$file = $_FILES['img'];
$tools = new Tools(); //ÕaÊÇÒ»¸oÎļþÉÏ´«Àa ËaeÒaÑ¡ÔñÒ»ÑuÄaϲ»¶µÄÉÏ´«*½Ê½
$logo_url = $tools->_upload_award("poll_img", $file, time());
$description = $_POST['description'];
$total = $_POST['total'];
$jump_url = $_POST['jump_url'];
$token = getAccessToken(); //ÕaÀiÊÇÎÒ*a×°µÄÒ»¸o»ñÈ¡ tokenµÄ *½*¨ ×oÁËʱ¼aÏÞÖÆ *ÀÖ¹³¬³oµ÷ÓôÎÊý
¡¡¡¡¡¡$Redpack = new addlotteryinfo_pub($token,SITE_URL.$logo_url);
¡¡¡¡ $time = time();
¡¡¡¡ $end = time()+60*24*60*60;//Á½¸oÔ ÕaÀiµÄ¿ªÊ¼ºÍ½aÊøʱ¼aÎҹ̶¨ÁË
¡¡¡¡$key = $Redpack->createNoncestr(); //key
¡¡$Redpack->setParameter('title', $title);
//»i¶¯±eÌa
$Redpack->setParameter('desc', $description);
//»i¶¯ÃeÊo
$Redpack->setParameter('begin_time', $time);
//¿ªÊ¼Ê±¼a
$Redpack->setParameter('expire_time', $end);
//½aÊøʱ¼a
$Redpack->setParameter('total', $total);
//ºi°u×ÜÊý
$Redpack->setParameter('jump_url', $jump_url);
//key
$Redpack->setParameter('key', $key);
$result = $Redpack->hbpreorder();
$result = (array)$result;
if($result['errcode']==0){
¡¡¡¡ $lottery_id = $result['lottery_id'];
$page_id = $result['page_id'];
//ÕaÀi¼ÇµÃ´aeÒ»ÏÂÊý¾Ý¿a£» ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡
}else{
//echo '´´½¨»i¶¯Ê§°Ü£º'.$result['errmsg'];
//ÕaÀiÊÇ´iÎoÌaʾ
}
2.Ԥϵ¥
½Ó¿Ú˵Ã÷
ÉeÖõ¥¸oºi°uµÄ½ð¶i£¬ÀaÐ͵ȣ¬Éu³Éºi°uÐÅÏ¢¡£Ô¤Ïµ¥Íe³Éºo£¬ÐeÒªÔÚ72СʱÄÚµ÷ÓÃjsapiÍe³É³eºi°uµÄ²Ù×÷¡££¨ºi°u¹ýÆÚʧЧºo£¬×ʽð»aÍ˻ص½ÉÌ»§²Æ¸¶Í¨Õʺš££(C)
½Ó¿Úµ÷ÓÃ˵Ã÷
*þÎñÆ÷¶Ëµ÷ÓÃ
httpÇeÇo*½Ê½: POST
https://api.mch.weixin.qq.com/mmpaymkttransfers/hbpreorder
POSTÊý¾Ý¸ñʽ£ºXML
ÐeÒªÉÌ»§Ö¤Êe
ÇeÇo²ÎÊý˵Ã÷
ÇeÇoʾÀý
<xml>
<sign><![CDATA[E1EE61A91C8E90F299DE6AE075D60A2D]]></sign>
<mch_billno><![CDATA[0010010404201411170000046545]]></mch_billno>
<mch_id><![CDATA[10000097]]></mch_id>
<wxappid><![CDATA[wxcbda96de0b165486]]></wxappid>
<send_name><![CDATA[send_name]]></send_name>
<hb_type><![CDATA[NORMAL]]></hb_type>
<auth_mchid><![CDATA[10000098]]></auth_mchid>
<auth_appid><![CDATA[wx7777777]]></auth_appid>
<total_amount><![CDATA[200]]></total_amount>
<amt_type><![CDATA[ALL_RAND]]></amt_type>
<total_num><![CDATA[3]]></total_num>
<wishing><![CDATA[¹§Ï²*¢²Æ ]]></wishing>
<act_name><![CDATA[ ÐÂÄeºi°u ]]></act_name>
<remark><![CDATA[ÐÂÄeºi°u ]]></remark>
<risk_cntl><![CDATA[NORMAL]]></risk_cntl>
<nonce_str><![CDATA[50780e0cca98c8c8e814883e5caa672e]]></nonce_str>
</xml>
*µ»ØÊý¾Ý˵Ã÷
ÒÔÏÂ×Ö¶ÎÔÚreturn_code ºÍresult_code¶¼ÎªSUCCESSµÄʱºoÓÐ*µ»Ø
³É¹¦Ê¾Àý
<xml>
<return_code><![CDATA[SUCCESS]]></return_code>
<return_msg><![CDATA[*¢*ųɹ¦.]]></return_msg>
<result_code><![CDATA[SUCCESS]]></result_code>
<err_code><![CDATA[0]]></err_code>
<err_code_des><![CDATA[*¢*ųɹ¦.]]></err_code_des>
<mch_billno><![CDATA[0010010404201411170000046545]]></mch_billno>
<mch_id>10010404</mch_id>
<wxappid><![CDATA[wx6fa7e3bab7e15415]]></wxappid>
<sp_ticket><![CDATA[0cca98c8c8e814883]]></sp_ticket>
<total_amount>3</total_amount>
<detail_id><![CDATA[001001040420141117000004888]]></detail_id>
<send_time><![CDATA[20150101080000]]></send_time>
</xml>
ʧ°ÜʾÀý
<xml>
<return_code><![CDATA[FAIL]]></return_code>
<return_msg><![CDATA[ϵͳ*±Ã¦,ÇeÉÔºoÔÙÊÔ.]]></return_msg>
<result_code><![CDATA[FAIL]]></result_code>
<err_code><![CDATA[268458547]]></err_code>
<err_code_des><![CDATA[ϵͳ*±Ã¦,ÇeÉÔºoÔÙÊÔ.]]></err_code_des>
<mch_billno><![CDATA[0010010404201411170000046542]]></mch_billno>
<mch_id>10010404</mch_id>
<wxappid><![CDATA[wx6fa7e3bab7e15415]]></wxappid>
<total_amount>3</total_amount>
</xml>
/**
* Ò¡Ò»Ò¡ºi°uԤϵ¥
* @author jiosen
*/
class Yhb_pub extends Wxpay_client_pub
{
var $code;//codeÂe£¬ÓÃÒÔ»ñÈ¡openid
var $openid;//Óû§µÄopenid
function __construct()
{
//ÉeÖýӿÚÁ´½Ó
$this->url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/hbpreorder";
//ÉeÖÃcurl³¬Ê±Ê±¼a
$this->curl_timeout = WxPayConf_pub::CURL_TIMEOUT;
}
/**
* Éu³É½Ó¿Ú²ÎÊýxml
*/
function createXml()
{
try
{
//¼i²a±ØÌi²ÎÊý
if($this->parameters["mch_billno"] == null)
{
throw new SDKRuntimeException("ȱÉÙ*¢ºi°u½Ó¿Ú±ØÌi²ÎÊýmch_billno£¡"."<br>");
}elseif ($this->parameters["send_name"] == null ) {
throw new SDKRuntimeException("ȱÉÙ*¢ºi°u½Ó¿Ú±ØÌi²ÎÊýsend_name£¡"."<br>");
}elseif ($this->parameters["total_amount"] == null) {
throw new SDKRuntimeException("ȱÉÙ*¢ºi°u½Ó¿Ú±ØÌi²ÎÊýtotal_amount£¡"."<br>");
}elseif ($this->parameters["total_num"] == null) {
throw new SDKRuntimeException("ȱÉÙ*¢ºi°u½Ó¿Ú±ØÌi²ÎÊýtotal_num£¡"."<br>");
}elseif ($this->parameters["wishing"] == null) {
throw new SDKRuntimeException("ȱÉÙ*¢ºi°u½Ó¿Ú±ØÌi²ÎÊýwishing£¡"."<br>");
}elseif ($this->parameters["act_name"] == null) {
throw new SDKRuntimeException("ȱÉÙ*¢ºi°u½Ó¿Ú±ØÌi²ÎÊýact_name£¡"."<br>");
}elseif ($this->parameters["remark"] == null) {
throw new SDKRuntimeException("ȱÉÙ*¢ºi°u½Ó¿Ú±ØÌi²ÎÊýremark£¡"."<br>");
}
$this->parameters["wxappid"] = WxPayConf_pub::APPID;//¹«ÖÚÕ˺ÅID
$this->parameters["mch_id"] = WxPayConf_pub::MCHID;//ÉÌ»§ºÅ
$this->parameters["nonce_str"] = $this->createNoncestr();//Ëae»u×Ö*u´®
//$this->parameters["re_openid"] = $this->openid;//Óû§openid
$this->parameters["hb_type"] = 'NORMAL';//ºi°uÀaÐÍ NORMAL-ÆÕͨºi°u£»GROUP-Áѱaºi°u(¿É*ÖÏiºi°u¸øºÃÓÑ£¬ÎÞ¹Ø×¢¹«ÖÚºÅÄÜÁ¦)¡£
$this->parameters["auth_mchid"] = '1000052601';//Ò¡ÖܱßÉÌ»§ºÅ
$this->parameters["auth_appid"] = 'wxbf42bd79c4391863';//Ò¡ÖÜ±ß appid
$this->parameters["risk_cntl"] = 'NORMAL';//*ç¿ØÉeÖÃ
$this->parameters["sign"] = $this->getSign($this->parameters);//Ç(C)Ãu
return $this->arrayToXml($this->parameters);
}catch (SDKRuntimeException $e)
{
die($e->errorMessage());
}
}
function hbpreorder()
{
$this->postXmlSSL();
$this->result = $this->xmlToArray($this->response);
return $this->result;
}
/**
* ×÷ÓãºÉu³É¿ÉÒÔ»ñµÃcodeµÄurl
*/
function createOauthUrlForCode($redirectUrl)
{
$urlObj["appid"] = WxPayConf_pub::APPID;
$urlObj["redirect_uri"] = "$redirectUrl";
$urlObj["response_type"] = "code";
$urlObj["scope"] = "snsapi_base";
$urlObj["state"] = "STATE"."#wechat_redirect";
$bizString = $this->formatBizQueryParaMap($urlObj, false);
return "https://open.weixin.qq.com/connect/oauth2/authorize?".$bizString;
}
/**
* ×÷ÓãºÉu³É¿ÉÒÔ»ñµÃopenidµÄurl
*/
function createOauthUrlForOpenid()
{
$urlObj["appid"] = WxPayConf_pub::APPID;
$urlObj["secret"] = WxPayConf_pub::APPSECRET;
$urlObj["code"] = $this->code;
$urlObj["grant_type"] = "authorization_code";
$bizString = $this->formatBizQueryParaMap($urlObj, false);
return "https://api.weixin.qq.com/sns/oauth2/access_token?".$bizString;
}
/**
* ×÷ÓãºÍ¨¹ýcurlÏo΢ÐÅÌa½»code£¬ÒÔ»ñÈ¡openid
*/
function getOpenid()
{
$url = $this->createOauthUrlForOpenid();
//³oʼ»¯curl
$ch = curl_init();
//ÉeÖó¬Ê±
curl_setopt($ch, CURLOP_TIMEOUT, $this->curl_timeout);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
//ÔËÐÐcurl£¬½a¹uÒÔjasonÐÎʽ*µ»Ø
$res = curl_exec($ch);
curl_close($ch);
//È¡³oopenid
$data = json_decode($res,true);
$this->openid = $data['openid'];
return $this->openid;
}
/**
* ×÷ÓãºÉeÖÃcode
*/
function setCode($code_)
{
$this->code = $code_;
}
}
ÕaÀiÐeҪעÒaµÄÊÇ auth_mchid ºÍ auth_appid ÒªÌiÒ¡Öܱßƽ̨¸ø³oµÄappid ºÍÉÌ»§ºÅ
µ÷Óà £¨ÕaÀi²»ÌuÇ°¶ËÒ³ÃaeÁË£(C)
$Redpack = new \Yhb_pub();
$Redpack->setParameter('mch_billno', WxPayConf_pub::MCHID.date('YmdHis').rand(1000, 9999));
//ÉÌ»§Ãu³Æ
$Redpack->setParameter('send_name', "ÉÌ»§Ãu³Æ");
//¸¶¿i½ð¶i
$Redpack->setParameter('total_amount', 100); //µ¥Î»*Ö
//ºi°u*¢*Å×ÜÈËÊý
$Redpack->setParameter('amt_type', "ALL_RAND");
$Redpack->setParameter('total_num', 1);
//ºi°u×£¸£Ói
$Redpack->setParameter('wishing', "Ò¡Ò»Ò¡Ëͺi°u");
//»i¶¯Ãu³Æ
$Redpack->setParameter('act_name', "Ò¡Ò»Ò¡Ëͺi°u");
//±¸×¢
$Redpack->setParameter('remark', "Ò¡Ò»Ò¡Ëͺi°u ±¸×¢");
$result = $Redpack->hbpreorder();
if($result[''])
3.¼Èeºi°u
½Ó¿Ú˵Ã÷
ÔÚµ÷ÓÃ"´´½¨ºi°u»i¶¯"½Ó¿ÚÖ®ºo£¬µ÷Óô˽ӿÚ¼Èeºi°uÐÅÏ¢¡£×¢Òa£¬´Ë½Ó¿Úÿ´Îµ÷Ó㬶¼»aÏoij¸o»i¶¯ÐÂÔoÒ»Åuºi°uÐÅÏ¢£¬Èç¹uºi°uÊýÉÙÓÚ100 ¸o£¬Çeͨ¹ýÒ»´Îµ÷ÓÃÌi¼ÓËuÓкi°uÐÅÏ¢¡£Èç¹uºi°uÊý´oÓÚ100£¬¿ÉÒÔ¶a´Îµ÷ÓýӿÚÌi¼Ó¡£Çe×¢ÒaÈ*±£¶a´Î¼ÈeµÄºi°uticket×ܵÄÊýÄ¿²»´oÓÚ´´½¨¸Ãºi°u»i¶¯ ʱÉeÖõÄtotalÖµ¡£
½Ó¿Úµ÷ÓÃ˵Ã÷
* þÎñÆ÷¶Ëµ÷ÓÃ**
httpÇeÇo*½Ê½: POST
URL:https://api.weixin.qq.com/shakearound/lottery/setprizebucket?access_token=ACCESSTOKEN
ÇeÇo²ÎÊý˵Ã÷
POST BODY£ºJSON¸ñʽµÄ½a¹¹Ìa
ÇeÇoʾÀý
Content-Type: application/json Post Body:
{
"lottery_id": "xxxxxxllllll",
"mchid": "10000098",
"sponsor_appid": "wx8888888888888888",
"prize_info_list": [
{
"ticket": "v1|ZiPs2l0hpMBp3uwGI1rwp45vOdz/V/zQ/00jP9MeWT+e47/q1FJjwCIP34frSjzOxAEzJ7k2CtAg1pmcShvkChBWqbThxPm6MBuzceoHtj79iHuHaEn0WAO+j4sXnXnbGswFOlDYWg1ngvrRYnCY3g=="
},
{
"ticket": "v1|fOhNUTap1oepSm5ap0hx1gmATM\/QX\/xn3sZWL7K+5Z10sbV5\/mZ4SwxwxbK2SPV32eLRvjd4ww1G3H5a+ypqRrySi+4oo97y63KoEQbRCPjbkyQBY8AYVyvD40V2b9slTQCm2igGY98mPe+VxZiayQ=="
}
]
}
*µ»ØÊý¾Ý˵Ã÷
ʾÀý
{
"errcode":0,
"errmsg":"",
"repeat_ticket_list":[
{
"ticket": "v1|ZiPs2l0hpMBp3uwGI1rwp45vOdz/V/zQ/00jP9MeWT+e47/q1FJjwCIP34frSjzOxAEzJ7k2CtAg1pmcShvkChBWqbThxPm6MBuzceoHtj79iHuHaEn0WAO+j4sXnXnbGswFOlDYWg1ngvrRYnCY3g=="
},
{
"ticket":"v1|ZiPs2l0zzXCsdfwe45dxCdHiukOdz/V/zQ/89xcnC5XnT+e47/q1FJjwCO4frSjzOxAEzJ7k2CtAg1pmcShvkChBWzc45dDGC32Dcxx4DGxczjDCGsdjowe9iHuaEn0WAO+GswFOlDYWg1ngvrRYnCY3g==" }
}
],
"success_num":100
}
/**
* Ò¡Ò»Ò¡ºi°u ¼Èeºi°u
* @author jiosen
*/
class lottery_pub extends Wxpay_client_pub
{
var $code;//codeÂe£¬ÓÃÒÔ»ñÈ¡openid
var $openid;//Óû§µÄopenid
function __construct($access_token)
{
//ÉeÖýӿÚÁ´½Ó
$this->url = "https://api.weixin.qq.com/shakearound/lottery/setprizebucket?access_token=".$access_token;
//ÉeÖÃcurl³¬Ê±Ê±¼a
$this->curl_timeout = WxPayConf_pub::CURL_TIMEOUT;
}
/**
* Éu³É½Ó¿Ú²ÎÊý json
*/
function createJson()
{
try
{
//¼i²a±ØÌi²ÎÊý
if($this->parameters["lottery_id"] == null)
{
throw new SDKRuntimeException("ȱÉÙ³e½±»i¶¯id lottery_id £¡"."<br>");
}else if(empty($this->parameters["prize_info_list"])){
throw new SDKRuntimeException("ȱÉÙ³e½±»i¶¯ºi°u prize_info_list £¡"."<br>");
}
$this->parameters["mchid"] = WxPayConf_pub::MCHID;//ÊÚȨÉÌ»§ºÅ
$this->parameters["sponsor_appid"] = WxPayConf_pub::APPID;//ÊÚȨÉϺÅappid
return json_encode($this->parameters);
//echo json_encode($this->parameters);die;
}catch (SDKRuntimeException $e)
{
die($e->errorMessage());
}
}
function setJsonArray($parameter, $parameterValue){
$this->parameters[$this->trimString($parameter)] = $parameterValue;
}
function hbpreorder()
{
$data = $this->createJson();
$result = $this->curl_post($this->url,$data);
$result = json_decode($result);
return $result;
}
function curl_post($url,$data)
{
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, 1);//*¢ËÍÒ»¸o³£¹aeµÄPostÇeÇo
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);//PostÌa½»µÄÊý¾Ý°u
$rv = curl_exec($curl);//Êa³oÄÚÈÝ
curl_close($curl);
return $rv;
}
/**
* ×÷ÓãºÉu³É¿ÉÒÔ»ñµÃcodeµÄurl
*/
function createOauthUrlForCode($redirectUrl)
{
$urlObj["appid"] = WxPayConf_pub::APPID;
$urlObj["redirect_uri"] = "$redirectUrl";
$urlObj["response_type"] = "code";
$urlObj["scope"] = "snsapi_base";
$urlObj["state"] = "STATE"."#wechat_redirect";
$bizString = $this->formatBizQueryParaMap($urlObj, false);
return "https://open.weixin.qq.com/connect/oauth2/authorize?".$bizString;
}
/**
* ×÷ÓãºÉu³É¿ÉÒÔ»ñµÃopenidµÄurl
*/
function createOauthUrlForOpenid()
{
$urlObj["appid"] = WxPayConf_pub::APPID;
$urlObj["secret"] = WxPayConf_pub::APPSECRET;
$urlObj["code"] = $this->code;
$urlObj["grant_type"] = "authorization_code";
$bizString = $this->formatBizQueryParaMap($urlObj, false);
return "https://api.weixin.qq.com/sns/oauth2/access_token?".$bizString;
}
/**
* ×÷ÓãºÍ¨¹ýcurlÏo΢ÐÅÌa½»code£¬ÒÔ»ñÈ¡openid
*/
function getOpenid()
{
$url = $this->createOauthUrlForOpenid();
//³oʼ»¯curl
$ch = curl_init();
//ÉeÖó¬Ê±
curl_setopt($ch, CURLOP_TIMEOUT, $this->curl_timeout);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
//ÔËÐÐcurl£¬½a¹uÒÔjasonÐÎʽ*µ»Ø
$res = curl_exec($ch);
curl_close($ch);
//È¡³oopenid
$data = json_decode($res,true);
$this->openid = $data['openid'];
return $this->openid;
}
/**
* ×÷ÓãºÉeÖÃcode
*/
function setCode($code_)
{
$this->code = $code_;
}
}
µ÷ÓÃ
<br>¡¡¡¡¡¡¡¡$token = getAccessToken();<br>¡¡¡¡¡¡¡¡$Redpack = new \lottery_pub($token);<br>¡¡¡¡¡¡¡¡$lottery_id = ''; //ÕaÀi¶ÁÈ¡Êý¾Ý¿aÈ¡³o´´½¨»i¶¯Ê±*µ»ØµÄ lottery_id
$Redpack->setParameter('lottery_id', $lottery_id);
//»i¶¯id
$prize_info_list =array(array('ticket'=>'ÕaÀiÈ¡³oԤϵ¥*µ»ØµÄsp_ticket'));
$Redpack->setJsonArray('prize_info_list', $prize_info_list);
//Ìa½»
$Redpack->hbpreorder();
ÇÀºi°uÒ³Ãae php
function getshakeinfo($access_token,$ticket){
$getshakeinfourl='https://api.weixin.qq.com/shakearound/user/getshakeinfo?access_token='.$access_token;
$jo=0;
if($access_token){
$data=array('ticket' =>$ticket);
$rd=$this->curl_post($getshakeinfourl,json_encode($data));
$jo=json_decode($rd);
}else{
echo 'access_token null';
}
return $jo;
}
¡¡¡¡¡¡ $ticket=$_GET['ticket'];//»ñ…¨Ée±¸ÐÅÏ¢£¬°uÀ¨ U UID ¡¢ major ¡¢ minor £¬ÒÔ¼°¾aÀe¡¢ openID µÈÐÅÏ¢
¡¡¡¡¡¡ $token = getAccessToken();
$shake=getshakeinfo($token,$ticket);
$openid=$shake->data->openid;
$jsapi = new Common_util_pub();
$noncestr = $jsapi->createNoncestr();
$parameters = array(
'lottery_id' =>'´´½¨»i¶¯Ê±ºo*µ»ØµÄ»i¶¯ID',
'noncestr'=>$noncestr,
'openid'=>$openid,
);
$signStr = $jsapi->formatBizQueryParaMap($parameters,false);
$key = '´´½¨»i¶¯Ê±ºoµÄkey';
$signStr=$signStr."&key;=".$key;
$sign = strtoupper(md5($signStr));
* ÉÏÒ»²½µ»ØµÄ²ÎÊýÌiÔÚÇÀºi°uhtmlÒ³Ãae**
<script type="text/javascript" src="http://zb.weixin.qq.com/app/shakehb/BeaconShakehbJsBridge.js">
</script>
<script type="text/javascript">
BeaconShakehbJsBridge.ready(function(){
//alert();
BeaconShakehbJsBridge.invoke('jumpHongbao',{lottery_id:"{$lottery_id}",noncestr:"{$noncestr}",openid:"{$openid}",sign:"{$sign}"});
});
</script>
ºi°u°o¶¨Óû§Ê¼þ֪ͨ¡¡¡¡¡¡¡¡¡¡
½Ó¿Ú˵Ã÷
Óû§½øÈeºi°uÒ³Ãaeʱ£¬ºǫ»a½«Ò»¸oºi°uticketºÍÓû§openid°o¶¨£¬Î¢ÐÅ»a°ÑÕa¸oʼþÍÆË͵½¿ª¢ÕßÌiдµÄURL£¨µÇ¼¹«ÖÚƽ̨½øÈe¿ª¢ÕßÖÐÐÄÉeÖã(C)¡£ÍÆËÍÄÚÈÝ°uº¬Óû§openid£¬ºi°u»i¶¯id£¬ºi°uticket¡¢½ð¶iÒÔ¼°ºi°u°o¶¨Ê±¼a¡£
×¢£ººi°u°o¶¨Óû§²»µÈͬÓÚÓû§ÁiÈ¡ºi°u¡£Óû§½øÈeºi°uÒ³Ãaeºo£¬ÓпÉÄܲ»²ðºi°u£¬µ«¸Ãºi°uticketÒѱ»°o¶¨£¬²»ÄÜÔÙ±»ÆaËuÓû§°o¶¨£¬¹ýÆÚºo»aÍË»ØÉÌ»§²Æ¸¶Í¨ÕË»§¡£
ÍÆËÍXMLÊý¾Ý°uʾÀý
<xml>
<ToUserName><![CDATA[toUser]]></ToUserName>
<FromUserName><![CDATA[fromUser]]></FromUserName>
<CreateTime>1442824314</CreateTime>
<MsgType><![CDATA[event]]></MsgType>
<Event><![CDATA[ShakearoundLotteryBind]]></Event>
<LotteryId><![CDATA[lotteryid]]></LotteryId>
<Ticket><![CDATA[ticket]]></Ticket>
<Money>88</Money>
<BindTime>1442824313</BindTime>
</xml>
Ìi¼Óʼþ´¦Ài¼´¿É
/**
* ʼþ´¦Ài
* @param unknown $object
* @return string
*/
public function handleEvent($object) {
// EventÊÇʼþÀaÐÍ(subscribe,LOCATION)
$oneEvent = $object->Event;
// EventKeyÊDz˵¥Ê¼þµÄkeyÖµ
$key = $object->EventKey;
// ¹Øעʼþ
if ($oneEvent == "subscribe" || $oneEvent == "SCAN") {
if(!empty($object->Ticket)) {
//ɨÂeʼþ
....
} else {
//¹Øעʼþ
....
}
}else if($oneEvent=="ShakearoundLotteryBind"){
//Ìi¼Óµ½Êý¾Ý¿a
}else if.......ÆaËuµÄʼþ......
}
Íe±ÏÁË.ʱ¼a±È½Ï´Òæ Ҳûʱ¼a×oÓÅ»¯ ´oÉñ¾¹ý˳±aÖ¸µ¼12 ÎҺôeµÄÓ¢ÎÄ»u´¡
ÏÂÃaeÌuÉÏÍeÕuWxPayPubHelper ¼¯³ÉÁËËuÓÐÖ§¸¶Àa ÅaÖÿÉÓÃ
<?php
/**
* ΢ÐÅÖ§¸¶°iÖu¿a
* ====================================================
* ½Ó¿Ú*ÖÈýÖÖÀaÐÍ£º
* ¡¾ÇeÇoÐͽӿڡ¿--Wxpay_client_
* ͳһ֧¸¶½Ó¿ÚÀa--UnifiedOrder
* ¶(C)µ¥²eѯ½Ó¿Ú--OrderQuery
* ÍË¿iÉeÇe½Ó¿Ú--Refund
* ÍË¿i²eѯ½Ó¿Ú--RefundQuery
* ¶ÔÕ˵¥½Ó¿Ú--DownloadBill
* ¶ÌÁ´½Óת»»½Ó¿Ú--ShortUrl
* ¡¾ÏiÓ¦Ðͽӿڡ¿--Wxpay_server_
* ͨÓÃ֪ͨ½Ó¿Ú--Notify
* NativeÖ§¸¶¡ª¡ªÇeÇoÉ̼һñÈ¡ÉÌÆ*ÐÅÏ¢½Ó¿Ú--NativeCall
* ¡¾ÆaËu¡¿
* ¾²Ì¬Á´½Ó¶þάÂe--NativeLink
* JSAPIÖ§¸¶--JsApi
* =====================================================
* ¡¾CommonUtil¡¿³£Óù¤¾ß£º
* trimString()£¬ÉeÖòÎÊýʱÐeÒªÓõ½µÄ×Ö*u´¦Àiº¯Êý
* createNoncestr()£¬²uÉuËae»u×Ö*u´®£¬²»³¤ÓÚ32λ
* formatBizQueryParaMap(),¸ñʽ»¯²ÎÊý£¬Ç(C)Ãu¹ý³ÌÐeÒªÓõ½
* getSign(),Éu³ÉÇ(C)Ãu
* arrayToXml(),arrayתxml
* xmlToArray(),xmlת array
* postXmlCurl(),ÒÔpost*½Ê½Ìa½»xmlµ½¶ÔÓ¦µÄ½Ó¿Úurl
* postXmlSSLCurl(),ʹÓÃÖ¤Êe£¬ÒÔpost*½Ê½Ìa½»xmlµ½¶ÔÓ¦µÄ½Ó¿Úurl
*/
include_once("SDKRuntimeException.php");
include_once("WxPay.pub.config.php");
/**
* ËuÓнӿڵĻuÀa
*/
class Common_util_pub
{
function __construct() {
}
function trimString($value)
{
$ret = null;
if (null != $value)
{
$ret = $value;
if (strlen($ret) == 0)
{
$ret = null;
}
}
return $ret;
}
/**
* ×÷Ó㺲uÉuËae»u×Ö*u´®£¬²»³¤ÓÚ32λ
*/
public function createNoncestr( $length = 32 )
{
$chars = "abcdefghijklmnopqrstuvwxyz0123456789";
$str ="";
for ( $i = 0; $i < $length; $i++ ) {
$str.= substr($chars, mt_rand(0, strlen($chars)-1), 1);
}
return $str;
}
/**
* ×÷Ó㺸ñʽ»¯²ÎÊý£¬Ç(C)Ãu¹ý³ÌÐeҪʹÓÃ
*/
function formatBizQueryParaMap($paraMap, $urlencode)
{
$buff = "";
ksort($paraMap);
foreach ($paraMap as $k => $v)
{
if($urlencode)
{
$v = urlencode($v);
}
//$buff .= strtolower($k) . "=" . $v . "&";
$buff .= $k . "=" . $v . "&";
}
$reqPar;
if (strlen($buff) > 0)
{
$reqPar = substr($buff, 0, strlen($buff)-1);
}
return $reqPar;
}
/**
* ×÷ÓãºÉu³ÉÇ(C)Ãu
*/
public function getSign($Obj)
{
foreach ($Obj as $k => $v)
{
$Parameters[$k] = $v;
}
//Ç(C)Ãu²½ÖeÒ»£º°´×ÖµaÐoÅÅÐo²ÎÊý
ksort($Parameters);
$String = $this->formatBizQueryParaMap($Parameters, false);
//echo '¡¾string1¡¿'.$String.'</br>';
//Ç(C)Ãu²½Öe¶þ£ºÔÚstringºo¼ÓÈeKEY
$String = $String."&key;=".WxPayConf_pub::KEY;
//echo "¡¾string2¡¿".$String."</br>";
//Ç(C)Ãu²½ÖeÈý£ºMD5¼ÓÃÜ
$String = md5($String);
//echo "¡¾string3¡¿ ".$String."</br>";
//Ç(C)Ãu²½ÖeËÄ£ºËuÓÐ×Ö*uתΪ´oд
$result_ = strtoupper($String);
//echo "¡¾result¡¿ ".$result_."</br>";
return $result_;
}
/**
* ×÷Óãºarrayתxml
*/
function arrayToXml($arr)
{
$xml = "<xml>";
foreach ($arr as $key=>$val)
{
if (is_numeric($val))
{
$xml.="<".$key.">".$val."</".$key.">";
}
else
$xml.="<".$key."><![CDATA[".$val."]]></".$key.">";
}
$xml.="</xml>";
return $xml;
}
/**
* ×÷Ó㺽«xmlתΪarray
*/
public function xmlToArray($xml)
{
//½«XMLתΪarray
$array_data = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
return $array_data;
}
/**
* ×÷ÓãºÒÔpost*½Ê½Ìa½»xmlµ½¶ÔÓ¦µÄ½Ó¿Úurl
*/
public function postXmlCurl($xml,$url,$second=30)
{
//³oʼ»¯curl
$ch = curl_init();
//ÉeÖó¬Ê±
curl_setopt($ch, CURLOP_TIMEOUT, $second);
//ÕaÀiÉeÖôuÀi£¬Èç¹uÓеĻ°
//curl_setopt($ch,CURLOPT_PROXY, '8.8.8.8');
//curl_setopt($ch,CURLOPT_PROXYPORT, 8080);
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);
//ÉeÖÃheader
curl_setopt($ch, CURLOPT_HEADER, FALSE);
//ÒªÇo½a¹uΪ×Ö*u´®ÇÒÊa³oµ½ÆÁÄ»ÉÏ
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
//postÌa½»*½Ê½
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
//ÔËÐÐcurl
$data = curl_exec($ch);
curl_close($ch);
//*µ»Ø½a¹u
if($data)
{
curl_close($ch);
return $data;
}
else
{
$error = curl_errno($ch);
echo "curl³o´i£¬´iÎoÂe:$error"."<br>";
echo "<a href='http://curl.haxx.se/libcurl/c/libcurl-errors.html'>´iÎoÔÒo²eѯ</a></br>";
curl_close($ch);
return false;
}
}
/**
* ×÷ÓãºÊ¹ÓÃÖ¤Êe£¬ÒÔpost*½Ê½Ìa½»xmlµ½¶ÔÓ¦µÄ½Ó¿Úurl
*/
function postXmlSSLCurl($xml,$url,$second=30)
{
$ch = curl_init();
//³¬Ê±Ê±¼a
curl_setopt($ch,CURLOPT_TIMEOUT,$second);
//ÕaÀiÉeÖôuÀi£¬Èç¹uÓеĻ°
//curl_setopt($ch,CURLOPT_PROXY, '8.8.8.8');
//curl_setopt($ch,CURLOPT_PROXYPORT, 8080);
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);
//ÉeÖÃheader
curl_setopt($ch,CURLOPT_HEADER,FALSE);
//ÒªÇo½a¹uΪ×Ö*u´®ÇÒÊa³oµ½ÆÁÄ»ÉÏ
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
//ÉeÖÃÖ¤Êe
//ʹÓÃÖ¤Êe£ºcert Óe key *Ö±ðÊoÓÚÁ½¸o.pemÎļþ
//ĬÈϸñʽΪPEM£¬¿ÉÒÔ×¢ÊÍ
// curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM');
// curl_setopt($ch,CURLOPT_SSLCERT,WxPayConf_pub::SSLCERT_PATH );
// //ĬÈϸñʽΪPEM£¬¿ÉÒÔ×¢ÊÍ
// curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM');
// curl_setopt($ch,CURLOPT_SSLKEY, WxPayConf_pub::SSLKEY_PATH);
curl_setopt($ch, CURLOPT_SSLCERT,WxPayConf_pub::SSLCERT_PATH);
curl_setopt($ch, CURLOPT_SSLKEY,WxPayConf_pub::SSLKEY_PATH);
curl_setopt($ch, CURLOPT_CAINFO, WxPayConf_pub::SSLCA_PATH); // CA¸uÖ¤Êe£¨ÓÃÀ´ÑeÖ¤µÄÍøÕ¾Ö¤ÊeÊÇ*ñÊÇCA°a²¼£(C)
//postÌa½»*½Ê½
curl_setopt($ch,CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_POSTFIELDS,$xml);
$data = curl_exec($ch);
//*µ»Ø½a¹u
if($data){
curl_close($ch);
return $data;
}
else {
$error = curl_errno($ch);
echo "curl³o´i£¬´iÎoÂe:$error"."<br>";
echo "<a href='http://curl.haxx.se/libcurl/c/libcurl-errors.html'>´iÎoÔÒo²eѯ</a></br>";
curl_close($ch);
return false;
}
}
/**
* ×÷Ó㺴oÓ¡Êý×e
*/
function printErr($wording='',$err='')
{
print_r('<pre>');
echo $wording."</br>";
var_dump($err);
print_r('</pre>');
}
}
/**
* ÇeÇoÐͽӿڵĻuÀa
*/
class Wxpay_client_pub extends Common_util_pub
{
var $parameters;//ÇeÇo²ÎÊý£¬ÀaÐÍΪ¹ØÁªÊý×e
public $response;//΢ÐÅ*µ»ØµÄÏiÓ¦
public $result;//*µ»Ø²ÎÊý£¬ÀaÐÍΪ¹ØÁªÊý×e
var $url;//½Ó¿ÚÁ´½Ó
var $curl_timeout;//curl³¬Ê±Ê±¼a
/**
* ×÷ÓãºÉeÖÃÇeÇo²ÎÊý
*/
function setParameter($parameter, $parameterValue)
{
$this->parameters[$this->trimString($parameter)] = $this->trimString($parameterValue);
}
/**
* ×÷ÓãºÉeÖñeÅaµÄÇeÇo²ÎÊý£¬Éu³ÉÇ(C)Ãu£¬Éu³É½Ó¿Ú²ÎÊýxml
*/
function createXml()
{
$this->parameters["appid"] = WxPayConf_pub::APPID;//¹«ÖÚÕ˺ÅID
$this->parameters["mch_id"] = WxPayConf_pub::MCHID;//ÉÌ»§ºÅ
$this->parameters["nonce_str"] = $this->createNoncestr();//Ëae»u×Ö*u´®
$this->parameters["sign"] = $this->getSign($this->parameters);//Ç(C)Ãu
return $this->arrayToXml($this->parameters);
}
/**
* ×÷ÓãºpostÇeÇoxml
*/
function postXml()
{
$xml = $this->createXml();
$this->response = $this->postXmlCurl($xml,$this->url,$this->curl_timeout);
return $this->response;
}
/**
* ×÷ÓãºÊ¹ÓÃÖ¤ÊepostÇeÇoxml
*/
function postXmlSSL()
{
$xml = $this->createXml();
$this->response = $this->postXmlSSLCurl($xml,$this->url,$this->curl_timeout);
return $this->response;
}
/**
* ×÷Ó㺻ñÈ¡½a¹u£¬Ä¬Èϲ»Ê¹ÓÃÖ¤Êe
*/
function getResult()
{
$this->postXml();
$this->result = $this->xmlToArray($this->response);
return $this->result;
}
}
/**
* ͳһ֧¸¶½Ó¿ÚÀa
*/
class UnifiedOrder_pub extends Wxpay_client_pub
{
function __construct()
{
//ÉeÖýӿÚÁ´½Ó
$this->url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
//ÉeÖÃcurl³¬Ê±Ê±¼a
$this->curl_timeout = WxPayConf_pub::CURL_TIMEOUT;
}
/**
* Éu³É½Ó¿Ú²ÎÊýxml
*/
function createXml()
{
try
{
//¼i²a±ØÌi²ÎÊý
if($this->parameters["out_trade_no"] == null)
{
throw new SDKRuntimeException("ȱÉÙͳһ֧¸¶½Ó¿Ú±ØÌi²ÎÊýout_trade_no£¡"."<br>");
}elseif($this->parameters["body"] == null){
throw new SDKRuntimeException("ȱÉÙͳһ֧¸¶½Ó¿Ú±ØÌi²ÎÊýbody£¡"."<br>");
}elseif ($this->parameters["total_fee"] == null ) {
throw new SDKRuntimeException("ȱÉÙͳһ֧¸¶½Ó¿Ú±ØÌi²ÎÊýtotal_fee£¡"."<br>");
}elseif ($this->parameters["notify_url"] == null) {
throw new SDKRuntimeException("ȱÉÙͳһ֧¸¶½Ó¿Ú±ØÌi²ÎÊýnotify_url£¡"."<br>");
}elseif ($this->parameters["trade_type"] == null) {
throw new SDKRuntimeException("ȱÉÙͳһ֧¸¶½Ó¿Ú±ØÌi²ÎÊýtrade_type£¡"."<br>");
}elseif ($this->parameters["trade_type"] == "JSAPI" &&
$this->parameters["openid"] == NULL){
throw new SDKRuntimeException("ͳһ֧¸¶½Ó¿ÚÖУ¬È±ÉÙ±ØÌi²ÎÊýopenid£¡trade_typeΪJSAPIʱ£¬openidΪ±ØÌi²ÎÊý£¡"."<br>");
}
$this->parameters["appid"] = WxPayConf_pub::APPID;//¹«ÖÚÕ˺ÅID
$this->parameters["mch_id"] = WxPayConf_pub::MCHID;//ÉÌ»§ºÅ
$this->parameters["spbill_create_ip"] = $_SERVER['REMOTE_ADDR'];//ÖÕ¶Ëip
$this->parameters["nonce_str"] = $this->createNoncestr();//Ëae»u×Ö*u´®
$this->parameters["sign"] = $this->getSign($this->parameters);//Ç(C)Ãu
return $this->arrayToXml($this->parameters);
}catch (SDKRuntimeException $e)
{
die($e->errorMessage());
}
}
/**
* »ñÈ¡prepay_id
*/
function getPrepayId()
{
$this->postXml();
$this->result = $this->xmlToArray($this->response);
$prepay_id = $this->result["prepay_id"];
return $prepay_id;
}
}
/**
* ¶(C)µ¥²eѯ½Ó¿Ú
*/
class OrderQuery_pub extends Wxpay_client_pub
{
function __construct()
{
//ÉeÖýӿÚÁ´½Ó
$this->url = "https://api.mch.weixin.qq.com/pay/orderquery";
//ÉeÖÃcurl³¬Ê±Ê±¼a
$this->curl_timeout = WxPayConf_pub::CURL_TIMEOUT;
}
/**
* Éu³É½Ó¿Ú²ÎÊýxml
*/
function createXml()
{
try
{
//¼i²a±ØÌi²ÎÊý
if($this->parameters["out_trade_no"] == null &&
$this->parameters["transaction_id"] == null)
{
throw new SDKRuntimeException("¶(C)µ¥²eѯ½Ó¿ÚÖУ¬out_trade_no¡¢transaction_idÖÁÉÙÌiÒ»¸o£¡"."<br>");
}
$this->parameters["appid"] = WxPayConf_pub::APPID;//¹«ÖÚÕ˺ÅID
$this->parameters["mch_id"] = WxPayConf_pub::MCHID;//ÉÌ»§ºÅ
$this->parameters["nonce_str"] = $this->createNoncestr();//Ëae»u×Ö*u´®
$this->parameters["sign"] = $this->getSign($this->parameters);//Ç(C)Ãu
return $this->arrayToXml($this->parameters);
}catch (SDKRuntimeException $e)
{
die($e->errorMessage());
}
}
}
/**
* ÍË¿iÉeÇe½Ó¿Ú
*/
class Refund_pub extends Wxpay_client_pub
{
function __construct() {
//ÉeÖýӿÚÁ´½Ó
$this->url = "https://api.mch.weixin.qq.com/secapi/pay/refund";
//ÉeÖÃcurl³¬Ê±Ê±¼a
$this->curl_timeout = WxPayConf_pub::CURL_TIMEOUT;
}
/**
* Éu³É½Ó¿Ú²ÎÊýxml
*/
function createXml()
{
try
{
//¼i²a±ØÌi²ÎÊý
if($this->parameters["out_trade_no"] == null && $this->parameters["transaction_id"] == null) {
throw new SDKRuntimeException("ÍË¿iÉeÇe½Ó¿ÚÖУ¬out_trade_no¡¢transaction_idÖÁÉÙÌiÒ»¸o£¡"."<br>");
}elseif($this->parameters["out_refund_no"] == null){
throw new SDKRuntimeException("ÍË¿iÉeÇe½Ó¿ÚÖУ¬È±ÉÙ±ØÌi²ÎÊýout_refund_no£¡"."<br>");
}elseif($this->parameters["total_fee"] == null){
throw new SDKRuntimeException("ÍË¿iÉeÇe½Ó¿ÚÖУ¬È±ÉÙ±ØÌi²ÎÊýtotal_fee£¡"."<br>");
}elseif($this->parameters["refund_fee"] == null){
throw new SDKRuntimeException("ÍË¿iÉeÇe½Ó¿ÚÖУ¬È±ÉÙ±ØÌi²ÎÊýrefund_fee£¡"."<br>");
}elseif($this->parameters["op_user_id"] == null){
throw new SDKRuntimeException("ÍË¿iÉeÇe½Ó¿ÚÖУ¬È±ÉÙ±ØÌi²ÎÊýop_user_id£¡"."<br>");
}
$this->parameters["appid"] = WxPayConf_pub::APPID;//¹«ÖÚÕ˺ÅID
$this->parameters["mch_id"] = WxPayConf_pub::MCHID;//ÉÌ»§ºÅ
$this->parameters["nonce_str"] = $this->createNoncestr();//Ëae»u×Ö*u´®
$this->parameters["sign"] = $this->getSign($this->parameters);//Ç(C)Ãu
return $this->arrayToXml($this->parameters);
}catch (SDKRuntimeException $e)
{
die($e->errorMessage());
}
}
/**
* ×÷Ó㺻ñÈ¡½a¹u£¬Ê¹ÓÃÖ¤ÊeͨÐÅ
*/
function getResult()
{
$this->postXmlSSL();
$this->result = $this->xmlToArray($this->response);
return $this->result;
}
}
/**
* ÍË¿i²eѯ½Ó¿Ú
*/
class RefundQuery_pub extends Wxpay_client_pub
{
function __construct() {
//ÉeÖýӿÚÁ´½Ó
$this->url = "https://api.mch.weixin.qq.com/pay/refundquery";
//ÉeÖÃcurl³¬Ê±Ê±¼a
$this->curl_timeout = WxPayConf_pub::CURL_TIMEOUT;
}
/**
* Éu³É½Ó¿Ú²ÎÊýxml
*/
function createXml()
{
try
{
if($this->parameters["out_refund_no"] == null &&
$this->parameters["out_trade_no"] == null &&
$this->parameters["transaction_id"] == null &&
$this->parameters["refund_id "] == null)
{
throw new SDKRuntimeException("ÍË¿i²eѯ½Ó¿ÚÖУ¬out_refund_no¡¢out_trade_no¡¢transaction_id¡¢refund_idËĸo²ÎÊý±ØÌiÒ»¸o£¡"."<br>");
}
$this->parameters["appid"] = WxPayConf_pub::APPID;//¹«ÖÚÕ˺ÅID
$this->parameters["mch_id"] = WxPayConf_pub::MCHID;//ÉÌ»§ºÅ
$this->parameters["nonce_str"] = $this->createNoncestr();//Ëae»u×Ö*u´®
$this->parameters["sign"] = $this->getSign($this->parameters);//Ç(C)Ãu
return $this->arrayToXml($this->parameters);
}catch (SDKRuntimeException $e)
{
die($e->errorMessage());
}
}
/**
* ×÷Ó㺻ñÈ¡½a¹u£¬Ê¹ÓÃÖ¤ÊeͨÐÅ
*/
function getResult()
{
$this->postXmlSSL();
$this->result = $this->xmlToArray($this->response);
return $this->result;
}
}
/**
* ¶ÔÕ˵¥½Ó¿Ú
*/
class DownloadBill_pub extends Wxpay_client_pub
{
function __construct()
{
//ÉeÖýӿÚÁ´½Ó
$this->url = "https://api.mch.weixin.qq.com/pay/downloadbill";
//ÉeÖÃcurl³¬Ê±Ê±¼a
$this->curl_timeout = WxPayConf_pub::CURL_TIMEOUT;
}
/**
* Éu³É½Ó¿Ú²ÎÊýxml
*/
function createXml()
{
try
{
if($this->parameters["bill_date"] == null )
{
throw new SDKRuntimeException("¶ÔÕ˵¥½Ó¿ÚÖУ¬È±ÉÙ±ØÌi²ÎÊýbill_date£¡"."<br>");
}
$this->parameters["appid"] = WxPayConf_pub::APPID;//¹«ÖÚÕ˺ÅID
$this->parameters["mch_id"] = WxPayConf_pub::MCHID;//ÉÌ»§ºÅ
$this->parameters["nonce_str"] = $this->createNoncestr();//Ëae»u×Ö*u´®
$this->parameters["sign"] = $this->getSign($this->parameters);//Ç(C)Ãu
return $this->arrayToXml($this->parameters);
}catch (SDKRuntimeException $e)
{
die($e->errorMessage());
}
}
/**
* ×÷Ó㺻ñÈ¡½a¹u£¬Ä¬Èϲ»Ê¹ÓÃÖ¤Êe
*/
function getResult()
{
$this->postXml();
$this->result = $this->xmlToArray($this->result_xml);
return $this->result;
}
}
/**
* ¶ÌÁ´½Óת»»½Ó¿Ú
*/
class ShortUrl_pub extends Wxpay_client_pub
{
function __construct()
{
//ÉeÖýӿÚÁ´½Ó
$this->url = "https://api.mch.weixin.qq.com/tools/shorturl";
//ÉeÖÃcurl³¬Ê±Ê±¼a
$this->curl_timeout = WxPayConf_pub::CURL_TIMEOUT;
}
/**
* Éu³É½Ó¿Ú²ÎÊýxml
*/
function createXml()
{
try
{
if($this->parameters["long_url"] == null )
{
throw new SDKRuntimeException("¶ÌÁ´½Óת»»½Ó¿ÚÖУ¬È±ÉÙ±ØÌi²ÎÊýlong_url£¡"."<br>");
}
$this->parameters["appid"] = WxPayConf_pub::APPID;//¹«ÖÚÕ˺ÅID
$this->parameters["mch_id"] = WxPayConf_pub::MCHID;//ÉÌ»§ºÅ
$this->parameters["nonce_str"] = $this->createNoncestr();//Ëae»u×Ö*u´®
$this->parameters["sign"] = $this->getSign($this->parameters);//Ç(C)Ãu
return $this->arrayToXml($this->parameters);
}catch (SDKRuntimeException $e)
{
die($e->errorMessage());
}
}
/**
* »ñÈ¡prepay_id
*/
function getShortUrl()
{
$this->postXml();
$prepay_id = $this->result["short_url"];
return $prepay_id;
}
}
/**
* ÏiÓ¦ÐͽӿڻuÀa
*/
class Wxpay_server_pub extends Common_util_pub
{
public $data;//½ÓÊÕµ½µÄÊý¾Ý£¬ÀaÐÍΪ¹ØÁªÊý×e
var $returnParameters;//*µ»Ø²ÎÊý£¬ÀaÐÍΪ¹ØÁªÊý×e
/**
* ½«Î¢ÐŵÄÇeÇoxmlת»»³É¹ØÁªÊý×e£¬ÒÔ*½±aÊý¾Ý´¦Ài
*/
function saveData($xml)
{
$this->data = $this->xmlToArray($xml);
}
function checkSign()
{
$tmpData = $this->data;
unset($tmpData['sign']);
$sign = $this->getSign($tmpData);//±¾µØÇ(C)Ãu
if ($this->data['sign'] == $sign) {
return TRUE;
}
return FALSE;
}
/**
* »ñȡ΢ÐŵÄÇeÇoÊý¾Ý
*/
function getData()
{
return $this->data;
}
/**
* ÉeÖÃ*µ»Ø΢ÐŵÄxmlÊý¾Ý
*/
function setReturnParameter($parameter, $parameterValue)
{
$this->returnParameters[$this->trimString($parameter)] = $this->trimString($parameterValue);
}
/**
* Éu³É½Ó¿Ú²ÎÊýxml
*/
function createXml()
{
return $this->arrayToXml($this->returnParameters);
}
/**
* ½«xmlÊý¾Ý*µ»Ø΢ÐÅ
*/
function returnXml()
{
$returnXml = $this->createXml();
return $returnXml;
}
}
/**
* ͨÓÃ֪ͨ½Ó¿Ú
*/
class Notify_pub extends Wxpay_server_pub
{
}
/**
* ÇeÇoÉ̼һñÈ¡ÉÌÆ*ÐÅÏ¢½Ó¿Ú
*/
class NativeCall_pub extends Wxpay_server_pub
{
/**
* Éu³É½Ó¿Ú²ÎÊýxml
*/
function createXml()
{
if($this->returnParameters["return_code"] == "SUCCESS"){
$this->returnParameters["appid"] = WxPayConf_pub::APPID;//¹«ÖÚÕ˺ÅID
$this->returnParameters["mch_id"] = WxPayConf_pub::MCHID;//ÉÌ»§ºÅ
$this->returnParameters["nonce_str"] = $this->createNoncestr();//Ëae»u×Ö*u´®
$this->returnParameters["sign"] = $this->getSign($this->returnParameters);//Ç(C)Ãu
}
return $this->arrayToXml($this->returnParameters);
}
/**
* »ñÈ¡product_id
*/
function getProductId()
{
$product_id = $this->data["product_id"];
return $product_id;
}
}
/**
* ¾²Ì¬Á´½Ó¶þάÂe
*/
class NativeLink_pub extends Common_util_pub
{
var $parameters;//¾²Ì¬Á´½Ó²ÎÊý
var $url;//¾²Ì¬Á´½Ó
function __construct()
{
}
/**
* ÉeÖòÎÊý
*/
function setParameter($parameter, $parameterValue)
{
$this->parameters[$this->trimString($parameter)] = $this->trimString($parameterValue);
}
/**
* Éu³ÉNativeÖ§¸¶Á´½Ó¶þάÂe
*/
function createLink()
{
try
{
if($this->parameters["product_id"] == null)
{
throw new SDKRuntimeException("ȱÉÙNativeÖ§¸¶¶þάÂeÁ´½Ó±ØÌi²ÎÊýproduct_id£¡"."<br>");
}
$this->parameters["appid"] = WxPayConf_pub::APPID;//¹«ÖÚÕ˺ÅID
$this->parameters["mch_id"] = WxPayConf_pub::MCHID;//ÉÌ»§ºÅ
$time_stamp = time();
$this->parameters["time_stamp"] = "$time_stamp";//ʱ¼a´Á
$this->parameters["nonce_str"] = $this->createNoncestr();//Ëae»u×Ö*u´®
$this->parameters["sign"] = $this->getSign($this->parameters);//Ç(C)Ãu
$bizString = $this->formatBizQueryParaMap($this->parameters, false);
$this->url = "weixin://wxpay/bizpayurl?".$bizString;
}catch (SDKRuntimeException $e)
{
die($e->errorMessage());
}
}
/**
* *µ»ØÁ´½Ó
*/
function getUrl()
{
$this->createLink();
return $this->url;
}
}
/**
* JSAPIÖ§¸¶¡ª¡ªH5ÍøÒ³¶Ëµ÷ÆðÖ§¸¶½Ó¿Ú
*/
class JsApi_pub extends Common_util_pub
{
var $code;//codeÂe£¬ÓÃÒÔ»ñÈ¡openid
var $openid;//Óû§µÄopenid
var $parameters;//jsapi²ÎÊý£¬¸ñʽΪjson
var $prepay_id;//ʹÓÃͳһ֧¸¶½Ó¿ÚµÃµ½µÄÔ¤Ö§¸¶id
var $curl_timeout;//curl³¬Ê±Ê±¼a
function __construct()
{
//ÉeÖÃcurl³¬Ê±Ê±¼a
$this->curl_timeout = WxPayConf_pub::CURL_TIMEOUT;
}
/**
* ×÷ÓãºÉu³É¿ÉÒÔ»ñµÃcodeµÄurl
*/
function createOauthUrlForCode($redirectUrl)
{
$urlObj["appid"] = WxPayConf_pub::APPID;
$urlObj["redirect_uri"] = "$redirectUrl";
$urlObj["response_type"] = "code";
$urlObj["scope"] = "snsapi_base";
$urlObj["state"] = "STATE"."#wechat_redirect";
$bizString = $this->formatBizQueryParaMap($urlObj, false);
return "https://open.weixin.qq.com/connect/oauth2/authorize?".$bizString;
}
/**
* ×÷ÓãºÉu³É¿ÉÒÔ»ñµÃopenidµÄurl
*/
function createOauthUrlForOpenid()
{
$urlObj["appid"] = WxPayConf_pub::APPID;
$urlObj["secret"] = WxPayConf_pub::APPSECRET;
$urlObj["code"] = $this->code;
$urlObj["grant_type"] = "authorization_code";
$bizString = $this->formatBizQueryParaMap($urlObj, false);
return "https://api.weixin.qq.com/sns/oauth2/access_token?".$bizString;
}
/**
* ×÷ÓãºÍ¨¹ýcurlÏo΢ÐÅÌa½»code£¬ÒÔ»ñÈ¡openid
*/
function getOpenid()
{
$url = $this->createOauthUrlForOpenid();
//³oʼ»¯curl
$ch = curl_init();
//ÉeÖó¬Ê±
curl_setopt($ch, CURLOP_TIMEOUT, $this->curl_timeout);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,FALSE);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,FALSE);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
//ÔËÐÐcurl£¬½a¹uÒÔjasonÐÎʽ*µ»Ø
$res = curl_exec($ch);
curl_close($ch);
//È¡³oopenid
$data = json_decode($res,true);
$this->openid = $data['openid'];
return $this->openid;
}
/**
* ×÷ÓãºÉeÖÃprepay_id
*/
function setPrepayId($prepayId)
{
$this->prepay_id = $prepayId;
}
/**
* ×÷ÓãºÉeÖÃcode
*/
function setCode($code_)
{
$this->code = $code_;
}
/**
* ×÷ÓãºÉeÖÃjsapiµÄ²ÎÊý
*/
public function getParameters()
{
$jsApiObj["appId"] = WxPayConf_pub::APPID;
$timeStamp = time();
$jsApiObj["timeStamp"] = "$timeStamp";
$jsApiObj["nonceStr"] = $this->createNoncestr();
$jsApiObj["package"] = "prepay_id=$this->prepay_id";
$jsApiObj["signType"] = "MD5";
$jsApiObj["paySign"] = $this->getSign($jsApiObj);
$this->parameters = json_encode($jsApiObj);
return $this->parameters;
}
}
/**
* ÏÖ½ðºi°u½Ó¿Ú
* @author gaoyl101
*/
class Redpack_pub extends Wxpay_client_pub
{
var $code;//codeÂe£¬ÓÃÒÔ»ñÈ¡openid
var $openid;//Óû§µÄopenid
function __construct()
{
//ÉeÖýӿÚÁ´½Ó
$this->url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack";
//ÉeÖÃcurl³¬Ê±Ê±¼a
$this->curl_timeout = WxPayConf_pub::CURL_TIMEOUT;
}
/**
* Éu³É½Ó¿Ú²ÎÊýxml
*/
function createXml()
{
try
{
//¼i²a±ØÌi²ÎÊý
if($this->parameters["mch_billno"] == null)
{
throw new SDKRuntimeException("ȱÉÙ*¢ºi°u½Ó¿Ú±ØÌi²ÎÊýmch_billno£¡"."<br>");
}elseif($this->parameters["nick_name"] == null){
throw new SDKRuntimeException("ȱÉÙ*¢ºi°u½Ó¿Ú±ØÌi²ÎÊýnick_name£¡"."<br>");
}elseif ($this->parameters["send_name"] == null ) {
throw new SDKRuntimeException("ȱÉÙ*¢ºi°u½Ó¿Ú±ØÌi²ÎÊýsend_name£¡"."<br>");
}elseif ($this->parameters["total_amount"] == null) {
throw new SDKRuntimeException("ȱÉÙ*¢ºi°u½Ó¿Ú±ØÌi²ÎÊýtotal_amount£¡"."<br>");
}elseif($this->parameters["min_value"] == null){
throw new SDKRuntimeException("ȱÉÙ*¢ºi°u½Ó¿Ú±ØÌi²ÎÊýmin_value£¡"."<br>");
}elseif ($this->parameters["max_value"] == null ) {
throw new SDKRuntimeException("ȱÉÙ*¢ºi°u½Ó¿Ú±ØÌi²ÎÊýmax_value£¡"."<br>");
}elseif ($this->parameters["total_num"] == null) {
throw new SDKRuntimeException("ȱÉÙ*¢ºi°u½Ó¿Ú±ØÌi²ÎÊýtotal_num£¡"."<br>");
}elseif ($this->parameters["wishing"] == null) {
throw new SDKRuntimeException("ȱÉÙ*¢ºi°u½Ó¿Ú±ØÌi²ÎÊýwishing£¡"."<br>");
}elseif ($this->parameters["act_name"] == null) {
throw new SDKRuntimeException("ȱÉÙ*¢ºi°u½Ó¿Ú±ØÌi²ÎÊýact_name£¡"."<br>");
}elseif ($this->parameters["remark"] == null) {
throw new SDKRuntimeException("ȱÉÙ*¢ºi°u½Ó¿Ú±ØÌi²ÎÊýremark£¡"."<br>");
}
$this->parameters["wxappid"] = WxPayConf_pub::APPID;//¹«ÖÚÕ˺ÅID
$this->parameters["mch_id"] = WxPayConf_pub::MCHID;//ÉÌ»§ºÅ
$this->parameters["client_ip"] = $_SERVER['REMOTE_ADDR'];//ÖÕ¶Ëip
$this->parameters["nonce_str"] = $this->createNoncestr();//Ëae»u×Ö*u´®
$this->parameters["re_openid"] = $this->parameters["re_openid"];
//$this->openid;//Óû§openid
$this->parameters["sign"] = $this->getSign($this->parameters);//Ç(C)Ãu
return $this->arrayToXml($this->parameters);
}catch (SDKRuntimeException $e)
{
die($e->errorMessage());
}
}
function sendRedpack()
{
$this->postXmlSSL();
$this->result = $this->xmlToArray($this->response);
return $this->result;
}
/**
* ×÷ÓãºÉu³É¿ÉÒÔ»ñµÃcodeµÄurl
*/
function createOauthUrlForCode($redirectUrl)
{
$urlObj["appid"] = WxPayConf_pub::APPID;
$urlObj["redirect_uri"] = "$redirectUrl";
$urlObj["response_type"] = "code";
$urlObj["scope"] = "snsapi_base";
$urlObj["state"] = "STATE"."#wechat_redirect";
$bizString = $this->formatBizQueryParaMap($urlObj, false);
return "https://open.weixin.qq.com/connect/oauth2/authorize?".$bizString;
}
/**
* ×÷ÓãºÉu³É¿ÉÒÔ»ñµÃopenidµÄurl
*/
function createOauthUrlForOpenid()
{
$urlObj["appid"] = WxPayConf_pub::APPID;
$urlObj["secret"] = WxPayConf_pub::APPSECRET;
$urlObj["code"] = $this->code;
$urlObj["grant_type"] = "authorization_code";
$bizString = $this->formatBizQueryParaMap($urlObj, false);
return "https://api.weixin.qq.com/sns/oauth2/access_token?".$bizString;
}
/**
* ×÷ÓãºÍ¨¹ýcurlÏo΢ÐÅÌa½»code£¬ÒÔ»ñÈ¡openid
*/
function getOpenid()
{
$url = $this->createOauthUrlForOpenid();
//³oʼ»¯curl
$ch = curl_init();
//ÉeÖó¬Ê±
curl_setopt($ch, CURLOP_TIMEOUT, $this->curl_timeout);