Skip to content

Commit

Permalink
公众号支付
Browse files Browse the repository at this point in the history
  • Loading branch information
dedemao authored Oct 23, 2018
1 parent 1d7cf79 commit 6460f1e
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions jsapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
$appid = 'xxxxx'; //微信支付申请对应的公众号的APPID
$appKey = 'xxxxx'; //微信支付申请对应的公众号的APP Key
$apiKey = 'xxxxx'; //https://pay.weixin.qq.com 帐户设置-安全设置-API安全-API密钥-设置API密钥

//①、获取用户openid
$wxPay = new WxpayService($mchid,$appid,$appKey,$apiKey);
$openId = $wxPay->GetOpenid(); //获取openid
Expand Down Expand Up @@ -32,11 +31,11 @@ function jsApiCall()
<?php echo $jsApiParameters; ?>,
function(res){
WeixinJSBridge.log(res.err_msg);
if(res.err_msg=='get_brand_wcpay_request:ok'){
alert('支付成功!');
}else{
alert('支付失败:'+res.err_code+res.err_desc+res.err_msg);
}
if(res.err_msg=='get_brand_wcpay_request:ok'){
alert('支付成功!');
}else{
alert('支付失败:'+res.err_code+res.err_desc+res.err_msg);
}
}
);
}
Expand Down Expand Up @@ -71,15 +70,13 @@ class WxpayService
protected $appKey;
protected $apiKey;
public $data = null;

public function __construct($mchid, $appid, $appKey,$key)
{
$this->mchid = $mchid; //https://pay.weixin.qq.com 产品中心-开发配置-商户号
$this->appid = $appid; //微信支付申请对应的公众号的APPID
$this->appKey = $appKey; //微信支付申请对应的公众号的APP Key
$this->apiKey = $key; //https://pay.weixin.qq.com 帐户设置-安全设置-API安全-API密钥-设置API密钥
}

/**
* 通过跳转获取用户的openid,跳转流程如下:
* 1、设置自己需要调回的url及其其他参数,跳转到微信服务器https://open.weixin.qq.com/connect/oauth2/authorize
Expand All @@ -103,7 +100,6 @@ public function GetOpenid()
return $openid;
}
}

/**
* 通过code从工作平台获取openid机器access_token
* @param string $code 微信跳转回来带上的code
Expand All @@ -119,7 +115,6 @@ public function GetOpenidFromMp($code)
$openid = $data['openid'];
return $openid;
}

/**
* 构造获取open和access_toke的url地址
* @param string $code,微信跳转带回的code
Expand All @@ -134,7 +129,6 @@ private function __CreateOauthUrlForOpenid($code)
$bizString = $this->ToUrlParams($urlObj);
return "https://api.weixin.qq.com/sns/oauth2/access_token?".$bizString;
}

/**
* 构造获取code的url连接
* @param string $redirectUrl 微信服务器回跳的url,需要url编码
Expand All @@ -150,7 +144,6 @@ private function __CreateOauthUrlForCode($redirectUrl)
$bizString = $this->ToUrlParams($urlObj);
return "https://open.weixin.qq.com/connect/oauth2/authorize?".$bizString;
}

/**
* 拼接签名字符串
* @param array $urlObj
Expand All @@ -166,7 +159,6 @@ private function ToUrlParams($urlObj)
$buff = trim($buff, "&");
return $buff;
}

/**
* 统一下单
* @param string $openid 调用【网页授权获取用户信息】接口获取到用户在该公众号下的Openid
Expand Down Expand Up @@ -220,7 +212,6 @@ public function createJsBizPackage($openid, $totalFee, $outTradeNo, $orderName,
$arr['paySign'] = self::getSign($arr, $config['key']);
return $arr;
}

public static function curlGet($url = '', $options = array())
{
$ch = curl_init($url);
Expand All @@ -236,7 +227,6 @@ public static function curlGet($url = '', $options = array())
curl_close($ch);
return $data;
}

public static function curlPost($url = '', $postData = '', $options = array())
{
if (is_array($postData)) {
Expand All @@ -258,7 +248,6 @@ public static function curlPost($url = '', $postData = '', $options = array())
curl_close($ch);
return $data;
}

public static function createNonceStr($length = 16)
{
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
Expand All @@ -280,7 +269,6 @@ public static function arrayToXml($arr)
$xml .= "</xml>";
return $xml;
}

public static function getSign($params, $key)
{
ksort($params, SORT_STRING);
Expand Down

0 comments on commit 6460f1e

Please sign in to comment.