118 lines
4.7 KiB
C#
118 lines
4.7 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Text;
|
|
using Newtonsoft.Json;
|
|
using Runtime;
|
|
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
|
|
namespace HK.FUJIFILM
|
|
{
|
|
public class NetworkManager : MonoManager<NetworkManager>
|
|
{
|
|
private string baseURL
|
|
{
|
|
get { return "http://3.109.226.137/api/createOrder"; }
|
|
}
|
|
|
|
public void Upload(Action<bool> callback)
|
|
{
|
|
var shoppingCart = ShoppingCartManager.Instance.ShoppingCart;
|
|
StartCoroutine(UploadOrder(shoppingCart.datas, "", shoppingCart.userName, shoppingCart.userModie, "fdsa@gmail.com", "dfsa",
|
|
shoppingCart.orderID, "", "", "", "Fujifilm", "Fujifilm", "123", "", callback));
|
|
}
|
|
|
|
private IEnumerator UploadOrder(List<ShoppingCartData> cartItems, string date, string name, string phone,
|
|
string email, string address, string orderid, string orderStatus, string credit_card_number,
|
|
string transaction_id,
|
|
string order_location, string location_kiosk, string payment_method, string order_status,
|
|
Action<bool> callback)
|
|
{
|
|
WWWForm form = new WWWForm();
|
|
|
|
//customer_name = "default name";
|
|
//customer_phone = "default phone";
|
|
|
|
form.AddField("client_name", name);
|
|
form.AddField("client_phone", phone);
|
|
form.AddField("client_email", email);
|
|
form.AddField("payment_method", payment_method);
|
|
form.AddField("credit_card", credit_card_number);
|
|
form.AddField("transaction_id", transaction_id);
|
|
form.AddField("order_location", order_location);
|
|
form.AddField("location_kiosk", location_kiosk);
|
|
form.AddField("client_delivery_address", address);
|
|
form.AddField("member_id", orderid);
|
|
form.AddField("eshop_order_created", date);
|
|
form.AddField("order_status", order_status);
|
|
|
|
for (int i = 0; i < cartItems.Count; i++)
|
|
{
|
|
int price = cartItems[i].bookAmount;
|
|
|
|
|
|
string productName = $"{cartItems[i].bookName}";
|
|
//if (cartItems[i].IsLivePrint)
|
|
// productName += " live print";
|
|
productName = productName.Replace('\n', ' ');
|
|
//if (cartItems[i].IsLivePrint)
|
|
// productName += " live print**";
|
|
form.AddField("product_name[" + i + "]", productName);
|
|
if (productName.Length < 45)
|
|
form.AddField("product_category[" + i + "]", productName);
|
|
else
|
|
form.AddField("product_category[" + i + "]", productName.Substring(0, 45));
|
|
//form.AddField("product_color[" + i + "]", cartItems[i].typedWords);
|
|
form.AddField("product_price[" + i + "]", price);
|
|
form.AddField("product_quantity[" + i + "]", cartItems[i].count);
|
|
form.AddField("product_total[" + i + "]", cartItems[i].bookAmount.ToString("0.0"));
|
|
// form.AddField("product_theme[" + i + "]", "null");
|
|
// form.AddField("product_remarks[" + i + "]", "null");
|
|
|
|
int c = 0;
|
|
string base64String;
|
|
string base64String1;
|
|
|
|
base64String = Convert.ToBase64String(cartItems[i].previewImage);
|
|
base64String1 = Convert.ToBase64String(cartItems[i].designImage[0]);
|
|
form.AddField("product_upload_media[" + i + "][" + c + "]", base64String1);
|
|
c++;
|
|
foreach (var bytes in cartItems[i].designImage)
|
|
{
|
|
var tmpStr = Convert.ToBase64String(bytes);
|
|
form.AddField("product_upload_media[" + i + "][" + c + "]", tmpStr);
|
|
c++;
|
|
}
|
|
|
|
form.AddField("product_preview1_base64[" + i + "]", base64String1);
|
|
form.AddField("product_preview2_base64[" + i + "]", base64String);
|
|
}
|
|
|
|
Debug.Log(Encoding.UTF8.GetString(form.data));
|
|
using (UnityWebRequest www = UnityWebRequest.Post(baseURL, form))
|
|
{
|
|
yield return www.SendWebRequest();
|
|
|
|
if (www.isNetworkError || www.isHttpError)
|
|
{
|
|
Debug.Log(www.error);
|
|
callback?.Invoke(false);
|
|
}
|
|
else
|
|
{
|
|
string data = www.downloadHandler.text;
|
|
|
|
Debug.Log(data);
|
|
|
|
|
|
Debug.Log("Form upload complete!");
|
|
callback?.Invoke(true);
|
|
}
|
|
}
|
|
|
|
yield return new WaitForSeconds(5);
|
|
}
|
|
}
|
|
} |