@@ -18,14 +18,14 @@ class WechatPay {
18
18
public $ appid ;
19
19
20
20
/** 商户身份ID */
21
- protected $ mch_id ;
21
+ public $ mch_id ;
22
22
23
23
/** 商户支付密钥Key */
24
- protected $ partnerKey ;
24
+ public $ partnerKey ;
25
25
26
26
/** 证书路径 */
27
- protected $ ssl_cer ;
28
- protected $ ssl_key ;
27
+ public $ ssl_cer ;
28
+ public $ ssl_key ;
29
29
30
30
/** 执行错误消息及代码 */
31
31
public $ errMsg ;
@@ -177,6 +177,52 @@ public function getPrepayId($openid, $body, $out_trade_no, $total_fee, $notify_u
177
177
return ($ trade_type === 'JSAPI ' ) ? $ result ['prepay_id ' ] : $ result ['code_url ' ];
178
178
}
179
179
180
+ /**
181
+ * 获取二维码预支付ID
182
+ * @param string $openid 用户openid,JSAPI必填
183
+ * @param string $body 商品标题
184
+ * @param string $out_trade_no 第三方订单号
185
+ * @param int $total_fee 订单总价
186
+ * @param string $notify_url 支付成功回调地址
187
+ * @param string $goods_tag 商品标记,代金券或立减优惠功能的参数
188
+ * @return bool|string
189
+ */
190
+ public function getQrcPrepayId ($ openid , $ body , $ out_trade_no , $ total_fee , $ notify_url , $ goods_tag = null ) {
191
+ $ postdata = array (
192
+ "body " => $ body ,
193
+ "out_trade_no " => $ out_trade_no ,
194
+ "total_fee " => $ total_fee ,
195
+ "notify_url " => $ notify_url ,
196
+ "trade_type " => 'NATIVE ' ,
197
+ "spbill_create_ip " => Tools::getAddress ()
198
+ );
199
+ empty ($ goods_tag ) || $ postdata ['goods_tag ' ] = $ goods_tag ;
200
+ empty ($ openid ) || $ postdata ['openid ' ] = $ openid ;
201
+ $ result = $ this ->getArrayResult ($ postdata , self ::MCH_BASE_URL . '/pay/unifiedorder ' );
202
+ if (false === $ this ->_parseResult ($ result ) || empty ($ result ['prepay_id ' ])) {
203
+ return false ;
204
+ }
205
+ return $ result ['prepay_id ' ];
206
+ }
207
+
208
+ /**
209
+ * 获取支付规二维码
210
+ * @param string $product_id 商户定义的商品id 或者订单号
211
+ * @return string
212
+ */
213
+ public function getQrcPayUrl ($ product_id ) {
214
+ $ data = array (
215
+ 'appid ' => $ this ->appid ,
216
+ 'mch_id ' => $ this ->mch_id ,
217
+ 'time_stamp ' => (string )time (),
218
+ 'nonce_str ' => Tools::createNoncestr (),
219
+ 'product_id ' => (string )$ product_id ,
220
+ );
221
+ $ data ['sign ' ] = Tools::getPaySign ($ data , $ this ->partnerKey );
222
+ return "weixin://wxpay/bizpayurl? " . http_build_query ($ data );
223
+ }
224
+
225
+
180
226
/**
181
227
* 创建JSAPI支付参数包
182
228
* @param string $prepay_id
0 commit comments