国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Home php教程 php手冊 PHP微信紅包API接口

PHP微信紅包API接口

Jun 06, 2016 pm 07:36 PM

這篇文章主要介紹了PHP微信紅包API接口,針對微信高級紅包接口,開發(fā)PHP版本的API接口的主要代碼進行分析,感興趣的小伙伴們可以參考一下

首先給大家看一看這個表格:

PHP微信紅包API接口

根據(jù)微信高級紅包接口,開發(fā)PHP版本的API接口,現(xiàn)在進行主要代碼分析。

紅包接口調(diào)用請求代碼,所有請求參數(shù)為必填參數(shù)與文檔對應:

class Wxapi { private $app_id = 'wxXXXXXXXXXXXX'; //公眾賬號appid,首先申請與之配套的公眾賬號 private $app_secret = 'XXXXXXXXXXXXXXXXXXXXXXXX';//公眾號secret,用戶獲取用戶授權(quán)token private $app_mchid = 'XXXXXXXX';//商戶號id function __construct(){ //do sth here.... } /** * 微信支付 * @param string $openid 用戶openid */ public function pay($re_openid) { include_once('WxHongBaoHelper.php'); $commonUtil = new CommonUtil(); $wxHongBaoHelper = new WxHongBaoHelper(); $wxHongBaoHelper->setParameter("nonce_str", $this->great_rand());//隨機字符串,丌長于 32 位 $wxHongBaoHelper->setParameter("mch_billno", $this->app_mchid.date('YmdHis').rand(1000, 9999));//訂單號 $wxHongBaoHelper->setParameter("mch_id", $this->app_mchid);//商戶號 $wxHongBaoHelper->setParameter("wxappid", $this->app_id); $wxHongBaoHelper->setParameter("nick_name", '紅包');//提供方名稱 $wxHongBaoHelper->setParameter("send_name", '紅包');//紅包發(fā)送者名稱 $wxHongBaoHelper->setParameter("re_openid", $re_openid);//相對于醫(yī)脈互通的openid $wxHongBaoHelper->setParameter("total_amount", 100);//付款金額,單位分 $wxHongBaoHelper->setParameter("min_value", 100);//最小紅包金額,單位分 $wxHongBaoHelper->setParameter("max_value", 100);//最大紅包金額,單位分 $wxHongBaoHelper->setParameter("total_num", 1);//紅包収放總?cè)藬?shù) $wxHongBaoHelper->setParameter("wishing", '感謝您參與紅包派發(fā)活動,祝您新年快樂!');//紅包祝福詫 $wxHongBaoHelper->setParameter("client_ip", '127.0.0.1');//調(diào)用接口的機器 Ip 地址 $wxHongBaoHelper->setParameter("act_name", '紅包活動');//活勱名稱 $wxHongBaoHelper->setParameter("remark", '快來搶!');//備注信息 $postXml = $wxHongBaoHelper->create_hongbao_xml(); $url = 'https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack'; $responseXml = $wxHongBaoHelper->curl_post_ssl($url, $postXml); //用作結(jié)果調(diào)試輸出 //echo htmlentities($responseXml,ENT_COMPAT,'UTF-8'); $responseObj = simplexml_load_string($responseXml, 'SimpleXMLElement', LIBXML_NOCDATA); return $responseObj->return_code; }

獲取隨機字符串方法:

/** * 生成隨機數(shù) */ public function great_rand(){ $str = '1234567890abcdefghijklmnopqrstuvwxyz'; for($i=0;$i

?簽名算法:

/** 例如: appid: wxd111665abv58f4f mch_id: 10000100 device_info: 1000 Body: test nonce_str: ibuaiVcKdpRxkhJA 第一步:對參數(shù)按照 key=value 的格式,并按照參數(shù)名 ASCII 字典序排序如下: stringA="appid=wxd930ea5d5a258f4f&body=test&device_info=1000&mch_i d=10000100&nonce_str=ibuaiVcKdpRxkhJA"; 第二步:拼接支付密鑰: stringSignTemp="stringA&key=192006250b4c09247ec02edce69f6a2d" sign=MD5(stringSignTemp).toUpperCase()="9A0A8659F005D6984697E2CA0A 9CF3B7" */ protected function get_sign(){ define('PARTNERKEY',"QSRXXXXXXXXXXXXXXXXXXXXX"); try { if (null == PARTNERKEY || "" == PARTNERKEY ) { throw new SDKRuntimeException("密鑰不能為空!" . "
"); } if($this->check_sign_parameters() == false) { //檢查生成簽名參數(shù) throw new SDKRuntimeException("生成簽名參數(shù)缺失!" . "
"); } $commonUtil = new CommonUtil(); ksort($this->parameters); $unSignParaString = $commonUtil->formatQueryParaMap($this->parameters, false); $md5SignUtil = new MD5SignUtil(); return $md5SignUtil->sign($unSignParaString,$commonUtil->trimString(PARTNERKEY)); }catch (SDKRuntimeException $e) { die($e->errorMessage()); } }

CURL請求以及發(fā)送證書:

function curl_post_ssl($url, $vars, $second=30,$aHeader=array()) { $ch = curl_init(); //超時時間 curl_setopt($ch,CURLOPT_TIMEOUT,$second); curl_setopt($ch,CURLOPT_RETURNTRANSFER, 1); //這里設置代理,如果有的話 curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false); curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,false); //cert 與 key 分別屬于兩個.pem文件 //請確保您的libcurl版本是否支持雙向認證,版本高于7.20.1 curl_setopt($ch,CURLOPT_SSLCERT,dirname(__FILE__).DIRECTORY_SEPARATOR.'zhengshu'.DIRECTORY_SEPARATOR.'apiclient_cert.pem'); curl_setopt($ch,CURLOPT_SSLKEY,dirname(__FILE__).DIRECTORY_SEPARATOR.'zhengshu'.DIRECTORY_SEPARATOR.'apiclient_key.pem'); curl_setopt($ch,CURLOPT_CAINFO,dirname(__FILE__).DIRECTORY_SEPARATOR.'zhengshu'.DIRECTORY_SEPARATOR.'rootca.pem'); if( count($aHeader) >= 1 ){ curl_setopt($ch, CURLOPT_HTTPHEADER, $aHeader); } curl_setopt($ch,CURLOPT_POST, 1); curl_setopt($ch,CURLOPT_POSTFIELDS,$vars); $data = curl_exec($ch); if($data){ curl_close($ch); return $data; } else { $error = curl_errno($ch); //echo "call faild, errorCode:$error\n"; curl_close($ch); return false; } }

入口文件:

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)