|
|
@@ -309,28 +309,46 @@ class WxService extends BaseService
|
|
|
|
|
|
public function appPay($openid, $out_trade_no, $description, $amount)
|
|
|
{
|
|
|
- $config = WxService::wxAppConfig();
|
|
|
- $body = [
|
|
|
- 'appid' => $config["appid"],
|
|
|
- 'mchid' => $config['mch_id'],
|
|
|
- 'description' => $description,
|
|
|
- 'out_trade_no' => $out_trade_no,
|
|
|
- 'notify_url' => "https://pbbaby.xunsoftware.com/api.php/api/callback/wxpay",
|
|
|
- 'amount' => [
|
|
|
- 'total' => fixed2Float($amount * 100),
|
|
|
- 'currency' => 'CNY'
|
|
|
- ],
|
|
|
- 'payer' => [
|
|
|
- "openid" => $openid
|
|
|
- ]
|
|
|
- ];
|
|
|
- return $this->ok([
|
|
|
- 'appId' => $config['appid'],
|
|
|
- 'timeStamp' => time(),
|
|
|
- 'nonceStr' => Formatter::nonce(),
|
|
|
- 'package' => 'prepay_id=21435325234534sdfdhasdg123',
|
|
|
- 'signType' => 'RSA'
|
|
|
- ]);
|
|
|
+ try {
|
|
|
+ $config = WxService::wxAppConfig();
|
|
|
+ $resp = $this->instance("app")
|
|
|
+ ->chain('v3/pay/transactions/app')
|
|
|
+ ->post(['json' => [
|
|
|
+ 'appid' => $config["appid"],
|
|
|
+ 'mchid' => $config['mch_id'],
|
|
|
+ 'description' => $description,
|
|
|
+ 'out_trade_no' => $out_trade_no,
|
|
|
+ 'notify_url' => "https://pbbaby.xunsoftware.com/api.php/api/callback/wxpay",
|
|
|
+ 'amount' => [
|
|
|
+ 'total' => fixed2Float($amount * 100),
|
|
|
+ 'currency' => 'CNY'
|
|
|
+ ],
|
|
|
+// 'payer' => [
|
|
|
+// "openid" => $openid
|
|
|
+// ]
|
|
|
+ ]]);
|
|
|
+ if (200 === $resp->getStatusCode()) {
|
|
|
+ $resp_data = json_decode($resp->getBody()->__toString(), true);
|
|
|
+ $res = [
|
|
|
+ 'appId' => $config['appid'],
|
|
|
+ 'timeStamp' => time(),
|
|
|
+ 'nonceStr' => Formatter::nonce(),
|
|
|
+ 'package' => 'prepay_id=' . $resp_data['prepay_id'],
|
|
|
+ 'signType' => 'RSA'
|
|
|
+ ];
|
|
|
+ $sign = $this->sign($res['appId'] . "\n" . $res["timeStamp"] . "\n" . $res["nonceStr"] . "\n" . $res["package"] . "\n", $config["mch_private_key_file_path"]);
|
|
|
+ $res["paySign"] = $sign;
|
|
|
+ return $this->ok($res);
|
|
|
+ }
|
|
|
+ return $this->fail("发起支付失败!");
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ // 进行错误处理
|
|
|
+ if ($e instanceof \GuzzleHttp\Exception\RequestException && $e->hasResponse()) {
|
|
|
+ $r = $e->getResponse();
|
|
|
+ return $this->fail($r->getBody()->__toString());
|
|
|
+ }
|
|
|
+ return $this->fail($e->getMessage());
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public function appRefund($out_trade_no, $description, $total_amount, $refund_amount)
|