weizong song 6 months ago
parent fe1f435a86
commit d3cd154f27

@ -12,6 +12,7 @@ class AlipayAccountForm extends Form
$this->add("id", Field::HIDDEN);
$this->add("name", Field::TEXT, ["label" => "名称", "rules" => "required"]);
$this->add("appid", Field::TEXT, ["label" => "应用ID", "rules" => "required"]);
$this->add("private_key", Field::TEXTAREA, ["label" => "应用私钥", "rules" => "required", "attr" => ["rows" => 4]]);
$this->add("public_key", Field::TEXTAREA, ["label" => "应用公钥", "rules" => "required", "attr" => ["rows" => 4]]);
$this->add("alipay_key", Field::TEXTAREA, ["label" => "支付宝密钥", "rules" => "required", "attr" => ["rows" => 4]]);
$this->add('buttons', 'buttongroup', ["splitted" => true, "buttons" => [

@ -1456,7 +1456,7 @@ class OrdersController extends CommonController
case "alipay":
$res = (new AlipayF2F())->pay($recharge);
$recharge->update([
"merchant_id" => env("ALI_APP_ID")
"merchant_id" => $order->alipayAccount->appid
]);
if ($res["status"]) {
return response()->json(true);

@ -6,6 +6,7 @@ use Alipay\EasySDK\Kernel\Factory;
use Alipay\EasySDK\Kernel\Util\ResponseChecker;
use Alipay\EasySDK\Kernel\Config;
use App\Events\RechargeSucceed;
use App\Models\AlipayAccount;
use App\Models\Recharge;
use App\Models\Refund;
use Illuminate\Support\Facades\Log;
@ -16,7 +17,9 @@ class AlipayF2F
{
try {
$auth_code = request()->auth_code;
$config = $this->getOptions();
$project = $recharge->project;
$alipayAccount = $project->alipayAccount;
$config = $this->getOptions($alipayAccount);
$result = Factory::setOptions($config)::payment()
->faceToFace()
@ -92,7 +95,11 @@ class AlipayF2F
public function refund(Refund $refund)
{
try {
$config = $this->getOptions();
$relatedRecharge = $refund->relatedRecharge;
$merchantId = $relatedRecharge->merchant_id;
$alipayAccount = AlipayAccount::where('appid', $merchantId)->withTrashed()->first();
$config = $this->getOptions($alipayAccount);
$result = Factory::setOptions($config)::payment()
->common()
@ -118,23 +125,23 @@ class AlipayF2F
}
}
public function getOptions()
public function getOptions(AlipayAccount $alipayAccount)
{
$options = new Config();
$options->protocol = 'https';
$options->gatewayHost = 'openapi.alipay.com';
$options->signType = 'RSA2';
// 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中
$options->merchantPrivateKey = env("ALI_APP_PRIVATE_KEY");
$options->appId = env("ALI_APP_ID");
//$options->alipayCertPath = env("ALI_CERT_ALIPAY");
//$options->alipayRootCertPath = env(" ALI_CERT_ROOT");
//$options->merchantCertPath = env("ALI_CERT_APP");
#$options->merchantPrivateKey = env("ALI_APP_PRIVATE_KEY");
#$options->appId = env("ALI_APP_ID");
#$options->alipayPublicKey = env("ALI_ALIPAY_KEY");
// 为避免私钥随源码泄露,推荐从文件中读取私钥字符串而不是写入源码中
$options->merchantPrivateKey = $alipayAccount->private_key;
$options->appId = $alipayAccount->appid;
//注:如果采用非证书模式,则无需赋值上面的三个证书路径,改为赋值如下的支付宝公钥字符串即可
$options->alipayPublicKey = env("ALI_ALIPAY_KEY");
$options->alipayPublicKey = $alipayAccount->alipay_key;
//可设置异步通知接收服务地址(可选)
$options->notifyUrl = "";

@ -215,6 +215,11 @@ class Orders extends SoftDeletesModel
return $this->hasOneThrough(WechatpayAccount::class, Project::class, "id", "id", "project_id", "wechatpay_account_id");
}
public function alipayAccount()
{
return $this->hasOneThrough(AlipayAccount::class, Project::class, "id", "id", "project_id", "alipay_account_id");
}
public function bed()
{
return $this->belongsTo(Bed::class);

@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class UpdateAlipayAccountAddAppPrivateKey extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('alipay_account', function (Blueprint $table) {
$table->string('private_key')->nullable()->comment('应用私钥')->after('appid');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
Loading…
Cancel
Save