PHP Class PFinal\Wechat\Service\PayService

Datei anzeigen Open project: pfinal/wechat Class Usage Examples

Public Methods

Method Description
arrayToXml ( $arr )
calc ( string $a, string $b, string $operator, integer $scale = 2 ) : string | integer 精度计算 默认使用bcmath扩展 如果没有启用bcmath扩展: 比较大小时转为整数比较、计算时使用number_format格式化返回值
createJsBizPackage ( string $openid, float $totalFee, string $outTradeNo, string $orderName, string $notifyUrl, $timestamp ) : string https://pay.weixin.qq.com/wiki/doc/api/wap.php?chapter=9_1
createNonceStr ( $length = 16 )
curlGet ( string $url = '', array $options = [] ) : mixed curl get
curlPost ( $url = '', $postData = '', $options = [] )
getConfig ( )
getSign ( $params, $key ) 例如: appid: wxd930ea5d5a258f4f mch_id: 10000100 device_info: 1000 Body: test nonce_str: ibuaiVcKdpRxkhJA 第一步:对参数按照 key=value 的格式,并按照参数名 ASCII 字典序排序如下: stringA="appid=wxd930ea5d5a258f4f&body=test&device_info=1000&mch_id=10000100&nonce_str=ibuaiVcKdpRxkhJA"; 第二步:拼接支付密钥: stringSignTemp="stringA&key=192006250b4c09247ec02edce69f6a2d" sign=MD5(stringSignTemp).toUpperCase()="9A0A8659F005D6984697E2CA0A9CF3B7"
notify ( ) : array 获取微信支付异步通知。(支付金额单位已转为元) 成功返回通知信息数组,失败返回null

Protected Methods

Method Description
formatQueryParaMap ( $paraMap, $urlEncode = false )

Method Details

arrayToXml() public static method

public static arrayToXml ( $arr )

calc() public static method

var_dump(floor((0.1 + 0.7) * 10)); // 7 var_dump(floor(\Rain\self::calc(\Rain\self::calc(0.1, 0.7, '+'), 10, '*'))); // 8
public static calc ( string $a, string $b, string $operator, integer $scale = 2 ) : string | integer
$a string
$b string
$operator string 操作符 支持: "+"、 "-"、 "*"、 "/"、 "comp"
$scale integer 小数精度位数,默认2位
return string | integer 加减乖除运算,返回string。比较大小时,返回int(相等返回0, $a大于$b返回1, 否则返回-1)

createJsBizPackage() public static method

https://pay.weixin.qq.com/wiki/doc/api/wap.php?chapter=9_1
public static createJsBizPackage ( string $openid, float $totalFee, string $outTradeNo, string $orderName, string $notifyUrl, $timestamp ) : string
$openid string 调用【网页授权获取用户信息】接口获取到用户在该公众号下的Openid
$totalFee float 收款总费用 单位元
$outTradeNo string 唯一的订单号
$orderName string 订单名称
$notifyUrl string 支付结果通知url 不要有问号 https://mp.weixin.qq.com/ 微信支付-开发配置-测试目录 测试目录 http://www.example.com/paytest/ 最后需要斜线,(需要精确到二级或三级目录)
return string

createNonceStr() public static method

public static createNonceStr ( $length = 16 )

curlGet() public static method

curl get
public static curlGet ( string $url = '', array $options = [] ) : mixed
$url string
$options array
return mixed

curlPost() public static method

public static curlPost ( $url = '', $postData = '', $options = [] )

formatQueryParaMap() protected static method

protected static formatQueryParaMap ( $paraMap, $urlEncode = false )

getConfig() public static method

public static getConfig ( )

getSign() public static method

例如: appid: wxd930ea5d5a258f4f mch_id: 10000100 device_info: 1000 Body: test nonce_str: ibuaiVcKdpRxkhJA 第一步:对参数按照 key=value 的格式,并按照参数名 ASCII 字典序排序如下: stringA="appid=wxd930ea5d5a258f4f&body=test&device_info=1000&mch_id=10000100&nonce_str=ibuaiVcKdpRxkhJA"; 第二步:拼接支付密钥: stringSignTemp="stringA&key=192006250b4c09247ec02edce69f6a2d" sign=MD5(stringSignTemp).toUpperCase()="9A0A8659F005D6984697E2CA0A9CF3B7"
public static getSign ( $params, $key )

notify() public static method

获取微信支付异步通知。(支付金额单位已转为元) 成功返回通知信息数组,失败返回null
public static notify ( ) : array
return array [ $mch_id //微信支付分配的商户号 $appid //微信分配的公众账号ID $openid //用户在商户appid下的唯一标识 $transaction_id //微信支付订单号 $out_trade_no //商户订单号 $total_fee //订单总金额单位默认为分,已转为元 $is_subscribe //用户是否关注公众账号,Y-关注,N-未关注,仅在公众账号类型支付有效 $attach //商家数据包,原样返回 $time_end //支付完成时间 ]