Skip to content

Commit 8280432

Browse files
committed
模拟登陆wechatext,
模拟二维码登陆wechatauth,旧版V2微信支付wechatpay移入旧版目录old_version,将不再继续更新。 #issue 167
1 parent 8a7b2f5 commit 8280432

8 files changed

+3167
-480
lines changed

Thinkphp/Wechat.class.php

+1-240
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
* 'token'=>'tokenaccesskey', //填写你设定的key
1010
* 'encodingaeskey'=>'encodingaeskey', //填写加密用的EncodingAESKey
1111
* 'appid'=>'wxdk1234567890', //填写高级调用功能的app id
12-
* 'appsecret'=>'xxxxxxxxxxxxxxxxxxx', //填写高级调用功能的密钥
13-
* 'partnerid'=>'88888888', //财付通商户身份标识
14-
* 'partnerkey'=>'', //财付通商户权限密钥Key
15-
* 'paysignkey'=>'' //商户签名密钥Key
12+
* 'appsecret'=>'xxxxxxxxxxxxxxxxxxx' //填写高级调用功能的密钥
1613
* );
1714
* $weObj = new Wechat($options);
1815
* $weObj->valid();
@@ -116,8 +113,6 @@ class Wechat
116113
const OAUTH_REFRESH_URL = '/sns/oauth2/refresh_token?';
117114
const OAUTH_USERINFO_URL = '/sns/oauth2/sns/userinfo?';
118115
const OAUTH_AUTH_URL = '/sns/auth?';
119-
const PAY_DELIVERNOTIFY = '/pay/delivernotify?';
120-
const PAY_ORDERQUERY = '/pay/orderquery?';
121116
///多客服相关地址
122117
const CUSTOM_SERVICE_GET_RECORD = '/customservice/getrecord?';
123118
const CUSTOM_SERVICE_GET_KFLIST = '/customservice/getkflist?';
@@ -183,9 +178,6 @@ public function __construct($options)
183178
$this->encodingAesKey = isset($options['encodingaeskey'])?$options['encodingaeskey']:'';
184179
$this->appid = isset($options['appid'])?$options['appid']:'';
185180
$this->appsecret = isset($options['appsecret'])?$options['appsecret']:'';
186-
$this->partnerid = isset($options['partnerid'])?$options['partnerid']:'';
187-
$this->partnerkey = isset($options['partnerkey'])?$options['partnerkey']:'';
188-
$this->paysignkey = isset($options['paysignkey'])?$options['paysignkey']:'';
189181
$this->debug = isset($options['debug'])?$options['debug']:false;
190182
$this->_logcallback = isset($options['logcallback'])?$options['logcallback']:false;
191183
}
@@ -1907,237 +1899,6 @@ public function getOauthAuth($access_token,$openid){
19071899
return false;
19081900
}
19091901

1910-
/**
1911-
* 获取签名
1912-
* @param array $arrdata 签名数组
1913-
* @param string $method 签名方法
1914-
* @return boolean|string 签名值
1915-
*/
1916-
public function getSignature($arrdata,$method="sha1") {
1917-
if (!function_exists($method)) return false;
1918-
ksort($arrdata);
1919-
$paramstring = "";
1920-
foreach($arrdata as $key => $value)
1921-
{
1922-
if(strlen($paramstring) == 0)
1923-
$paramstring .= $key . "=" . $value;
1924-
else
1925-
$paramstring .= "&" . $key . "=" . $value;
1926-
}
1927-
$paySign = $method($paramstring);
1928-
return $paySign;
1929-
}
1930-
1931-
/**
1932-
* 生成随机字串
1933-
* @param number $length 长度,默认为16,最长为32字节
1934-
* @return string
1935-
*/
1936-
public function generateNonceStr($length=16){
1937-
// 密码字符集,可任意添加你需要的字符
1938-
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
1939-
$str = "";
1940-
for($i = 0; $i < $length; $i++)
1941-
{
1942-
$str .= $chars[mt_rand(0, strlen($chars) - 1)];
1943-
}
1944-
return $str;
1945-
}
1946-
1947-
/**
1948-
* 生成原生支付url
1949-
* @param number $productid 商品编号,最长为32字节
1950-
* @return string
1951-
*/
1952-
public function createNativeUrl($productid){
1953-
$nativeObj["appid"] = $this->appid;
1954-
$nativeObj["appkey"] = $this->paysignkey;
1955-
$nativeObj["productid"] = urlencode($productid);
1956-
$nativeObj["timestamp"] = time();
1957-
$nativeObj["noncestr"] = $this->generateNonceStr();
1958-
$nativeObj["sign"] = $this->getSignature($nativeObj);
1959-
unset($nativeObj["appkey"]);
1960-
$bizString = "";
1961-
foreach($nativeObj as $key => $value)
1962-
{
1963-
if(strlen($bizString) == 0)
1964-
$bizString .= $key . "=" . $value;
1965-
else
1966-
$bizString .= "&" . $key . "=" . $value;
1967-
}
1968-
return "weixin://wxpay/bizpayurl?".$bizString;
1969-
//weixin://wxpay/bizpayurl?sign=XXXXX&appid=XXXXXX&productid=XXXXXX&timestamp=XXXXXX&noncestr=XXXXXX
1970-
}
1971-
1972-
1973-
/**
1974-
* 生成订单package字符串
1975-
* @param string $out_trade_no 必填,商户系统内部的订单号,32个字符内,确保在商户系统唯一
1976-
* @param string $body 必填,商品描述,128 字节以下
1977-
* @param int $total_fee 必填,订单总金额,单位为分
1978-
* @param string $notify_url 必填,支付完成通知回调接口,255 字节以内
1979-
* @param string $spbill_create_ip 必填,用户终端IP,IPV4字串,15字节内
1980-
* @param int $fee_type 必填,现金支付币种,默认1:人民币
1981-
* @param string $bank_type 必填,银行通道类型,默认WX
1982-
* @param string $input_charset 必填,传入参数字符编码,默认UTF-8,取值有UTF-8和GBK
1983-
* @param string $time_start 交易起始时间,订单生成时间,格式yyyyMMddHHmmss
1984-
* @param string $time_expire 交易结束时间,也是订单失效时间
1985-
* @param int $transport_fee 物流费用,单位为分
1986-
* @param int $product_fee 商品费用,单位为分,必须保证 transport_fee + product_fee=total_fee
1987-
* @param string $goods_tag 商品标记,优惠券时可能用到
1988-
* @param string $attach 附加数据,notify接口原样返回
1989-
* @return string
1990-
*/
1991-
public function createPackage($out_trade_no,$body,$total_fee,$notify_url,$spbill_create_ip,$fee_type=1,$bank_type="WX",$input_charset="UTF-8",$time_start="",$time_expire="",$transport_fee="",$product_fee="",$goods_tag="",$attach=""){
1992-
$arrdata = array("bank_type" => $bank_type, "body" => $body, "partner" => $this->partnerid, "out_trade_no" => $out_trade_no, "total_fee" => $total_fee, "fee_type" => $fee_type, "notify_url" => $notify_url, "spbill_create_ip" => $spbill_create_ip, "input_charset" => $input_charset);
1993-
if ($time_start) $arrdata['time_start'] = $time_start;
1994-
if ($time_expire) $arrdata['time_expire'] = $time_expire;
1995-
if ($transport_fee) $arrdata['transport_fee'] = $transport_fee;
1996-
if ($product_fee) $arrdata['product_fee'] = $product_fee;
1997-
if ($goods_tag) $arrdata['goods_tag'] = $goods_tag;
1998-
if ($attach) $arrdata['attach'] = $attach;
1999-
ksort($arrdata);
2000-
$paramstring = "";
2001-
foreach($arrdata as $key => $value)
2002-
{
2003-
if(strlen($paramstring) == 0)
2004-
$paramstring .= $key . "=" . $value;
2005-
else
2006-
$paramstring .= "&" . $key . "=" . $value;
2007-
}
2008-
$stringSignTemp = $paramstring . "&key=" . $this->partnerkey;
2009-
$signValue = strtoupper(md5($stringSignTemp));
2010-
$package = http_build_query($arrdata) . "&sign=" . $signValue;
2011-
return $package;
2012-
}
2013-
2014-
/**
2015-
* 支付签名(paySign)生成方法
2016-
* @param string $package 订单详情字串
2017-
* @param string $timeStamp 当前时间戳(需与JS输出的一致)
2018-
* @param string $nonceStr 随机串(需与JS输出的一致)
2019-
* @return string 返回签名字串
2020-
*/
2021-
public function getPaySign($package, $timeStamp, $nonceStr){
2022-
$arrdata = array("appid" => $this->appid, "timestamp" => $timeStamp, "noncestr" => $nonceStr, "package" => $package, "appkey" => $this->paysignkey);
2023-
$paySign = $this->getSignature($arrdata);
2024-
return $paySign;
2025-
}
2026-
2027-
/**
2028-
* 回调通知签名验证
2029-
* @param array $orderxml 返回的orderXml的数组表示,留空则自动从post数据获取
2030-
* @return boolean
2031-
*/
2032-
public function checkOrderSignature($orderxml=''){
2033-
if (!$orderxml) {
2034-
$postStr = file_get_contents("php://input");
2035-
if (!empty($postStr)) {
2036-
$orderxml = (array)simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
2037-
} else return false;
2038-
}
2039-
$arrdata = array('appid'=>$orderxml['AppId'],'appkey'=>$this->paysignkey,'timestamp'=>$orderxml['TimeStamp'],'noncestr'=>$orderxml['NonceStr'],'openid'=>$orderxml['OpenId'],'issubscribe'=>$orderxml['IsSubscribe']);
2040-
$paySign = $this->getSignature($arrdata);
2041-
if ($paySign!=$orderxml['AppSignature']) return false;
2042-
return true;
2043-
}
2044-
2045-
/**
2046-
* 发货通知
2047-
* @param string $openid 用户open_id
2048-
* @param string $transid 交易单号
2049-
* @param string $out_trade_no 第三方订单号
2050-
* @param int $status 0:发货失败;1:已发货
2051-
* @param string $msg 失败原因
2052-
* @return boolean|array
2053-
*/
2054-
public function sendPayDeliverNotify($openid,$transid,$out_trade_no,$status=1,$msg='ok'){
2055-
if (!$this->access_token && !$this->checkAuth()) return false;
2056-
$postdata = array(
2057-
"appid"=>$this->appid,
2058-
"appkey"=>$this->paysignkey,
2059-
"openid"=>$openid,
2060-
"transid"=>strval($transid),
2061-
"out_trade_no"=>strval($out_trade_no),
2062-
"deliver_timestamp"=>strval(time()),
2063-
"deliver_status"=>strval($status),
2064-
"deliver_msg"=>$msg,
2065-
);
2066-
$postdata['app_signature'] = $this->getSignature($postdata);
2067-
$postdata['sign_method'] = 'sha1';
2068-
unset($postdata['appkey']);
2069-
$result = $this->http_post(self::API_BASE_URL_PREFIX.self::PAY_DELIVERNOTIFY.'access_token='.$this->access_token,self::json_encode($postdata));
2070-
if ($result)
2071-
{
2072-
$json = json_decode($result,true);
2073-
if (!$json || !empty($json['errcode'])) {
2074-
$this->errCode = $json['errcode'];
2075-
$this->errMsg = $json['errmsg'];
2076-
return false;
2077-
}
2078-
return $json;
2079-
}
2080-
return false;
2081-
}
2082-
2083-
/**
2084-
* 查询订单信息
2085-
* @param string $out_trade_no 订单号
2086-
* @return boolean|array
2087-
*/
2088-
public function getPayOrder($out_trade_no) {
2089-
if (!$this->access_token && !$this->checkAuth()) return false;
2090-
$sign = strtoupper(md5("out_trade_no=$out_trade_no&partner={$this->partnerid}&key={$this->partnerkey}"));
2091-
$postdata = array(
2092-
"appid"=>$this->appid,
2093-
"appkey"=>$this->paysignkey,
2094-
"package"=>"out_trade_no=$out_trade_no&partner={$this->partnerid}&sign=$sign",
2095-
"timestamp"=>strval(time()),
2096-
);
2097-
$postdata['app_signature'] = $this->getSignature($postdata);
2098-
$postdata['sign_method'] = 'sha1';
2099-
unset($postdata['appkey']);
2100-
$result = $this->http_post(self::API_BASE_URL_PREFIX.self::PAY_ORDERQUERY.'access_token='.$this->access_token,self::json_encode($postdata));
2101-
if ($result)
2102-
{
2103-
$json = json_decode($result,true);
2104-
if (!$json || !empty($json['errcode'])) {
2105-
$this->errCode = $json['errcode'];
2106-
$this->errMsg = $json['errmsg'].json_encode($postdata);
2107-
return false;
2108-
}
2109-
return $json["order_info"];
2110-
}
2111-
return false;
2112-
}
2113-
2114-
/**
2115-
* 获取收货地址JS的签名
2116-
* @tutorial 参考weixin.js脚本的WeixinJS.editAddress方法调用
2117-
* @param string $appId
2118-
* @param string $url
2119-
* @param int $timeStamp
2120-
* @param string $nonceStr
2121-
* @param string $user_token
2122-
* @return Ambigous <boolean, string>
2123-
*/
2124-
public function getAddrSign($url, $timeStamp, $nonceStr, $user_token=''){
2125-
if (!$user_token) $user_token = $this->user_token;
2126-
if (!$user_token) {
2127-
$this->errMsg = 'no user access token found!';
2128-
return false;
2129-
}
2130-
$url = htmlspecialchars_decode($url);
2131-
$arrdata = array(
2132-
'appid'=>$this->appid,
2133-
'url'=>$url,
2134-
'timestamp'=>strval($timeStamp),
2135-
'noncestr'=>$nonceStr,
2136-
'accesstoken'=>$user_token
2137-
);
2138-
return $this->getSignature($arrdata);
2139-
}
2140-
21411902
/**
21421903
* 模板消息 设置所属行业
21431904
* @param int $id1 公众号模板消息所属行业编号,参看官方开发文档 行业代码

0 commit comments

Comments
 (0)