/** * <summary> * Creates a new empty SMS message, to be configured and sent later on. * <para> * </para> * </summary> * <param name="recipient"> * a text string with the recipient phone number, either as a * national number, or in international format starting with a plus sign * </param> * <returns> * <c>YAPI.SUCCESS</c> when the call succeeds. * </returns> * <para> * On failure, throws an exception or returns a negative error code. * </para> */ public virtual async Task <YSms> newMessage(string recipient) { YSms sms; sms = new YSms(this); await sms.set_recipient(recipient); return(sms); }
/** * <summary> * Sends a regular text SMS, with standard parameters. * <para> * This function can send messages * of more than 160 characters, using SMS concatenation. ISO-latin accented characters * are supported. For sending messages with special unicode characters such as asian * characters and emoticons, use <c>newMessage</c> to create a new message and define * the content of using methods <c>addText</c> and <c>addUnicodeData</c>. * </para> * </summary> * <param name="recipient"> * a text string with the recipient phone number, either as a * national number, or in international format starting with a plus sign * </param> * <param name="message"> * the text to be sent in the message * </param> * <returns> * <c>YAPI.SUCCESS</c> when the call succeeds. * </returns> * <para> * On failure, throws an exception or returns a negative error code. * </para> */ public virtual async Task <int> sendTextMessage(string recipient, string message) { YSms sms; sms = new YSms(this); await sms.set_recipient(recipient); await sms.addText(message); return(await sms.send()); }
public virtual async Task <YSms> fetchPdu(int slot) { byte[] binPdu; List <string> arrPdu = new List <string>(); string hexPdu; YSms sms; binPdu = await this._download("sms.json?pos=" + Convert.ToString(slot) + "&len=1"); arrPdu = this.imm_json_get_array(binPdu); hexPdu = this.imm_decode_json_string(arrPdu[0]); sms = new YSms(this); await sms.set_slot(slot); await sms.parsePdu(YAPIContext.imm_hexStrToBin(hexPdu)); return(sms); }
public virtual async Task <int> generateParts() { int udhsize; int udlen; int mss; int partno; int partlen; byte[] newud; byte[] newudh; YSms newpdu; int i; int wpos; udhsize = (_udh).Length; udlen = (_udata).Length; mss = 140 - 1 - 5 - udhsize; if (_alphab == 0) { mss = (((mss * 8 - 6)) / (7)); } _npdu = (((udlen + mss - 1)) / (mss)); _parts.Clear(); partno = 0; wpos = 0; while (wpos < udlen) { partno = partno + 1; newudh = new byte[5 + udhsize]; newudh[0] = (byte)(0 & 0xff); // IEI: concatenated message newudh[1] = (byte)(3 & 0xff); // IEDL: 3 bytes newudh[2] = (byte)(_mref & 0xff); newudh[3] = (byte)(_npdu & 0xff); newudh[4] = (byte)(partno & 0xff); i = 0; while (i < udhsize) { newudh[5 + i] = (byte)(_udh[i] & 0xff); i = i + 1; } if (wpos + mss < udlen) { partlen = mss; } else { partlen = udlen - wpos; } newud = new byte[partlen]; i = 0; while (i < partlen) { newud[i] = (byte)(_udata[wpos] & 0xff); wpos = wpos + 1; i = i + 1; } newpdu = new YSms(_mbox); await newpdu.set_received(await this.isReceived()); await newpdu.set_smsc(await this.get_smsc()); await newpdu.set_msgRef(await this.get_msgRef()); await newpdu.set_sender(await this.get_sender()); await newpdu.set_recipient(await this.get_recipient()); await newpdu.set_protocolId(await this.get_protocolId()); await newpdu.set_dcs(await this.get_dcs()); await newpdu.set_timestamp(await this.get_timestamp()); await newpdu.set_userDataHeader(newudh); await newpdu.set_userData(newud); _parts.Add(newpdu); } return(YAPI.SUCCESS); }
public virtual async Task <int> checkNewMessages() { string bitmapStr; byte[] prevBitmap; byte[] newBitmap; int slot; int nslots; int pduIdx; int idx; int bitVal; int prevBit; int i; int nsig; int cnt; string sig; List <YSms> newArr = new List <YSms>(); List <YSms> newMsg = new List <YSms>(); List <YSms> newAgg = new List <YSms>(); List <string> signatures = new List <string>(); YSms sms; bitmapStr = await this.get_slotsBitmap(); if (bitmapStr == _prevBitmapStr) { return(YAPI.SUCCESS); } prevBitmap = YAPIContext.imm_hexStrToBin(_prevBitmapStr); newBitmap = YAPIContext.imm_hexStrToBin(bitmapStr); _prevBitmapStr = bitmapStr; nslots = 8 * (newBitmap).Length; newArr.Clear(); newMsg.Clear(); signatures.Clear(); nsig = 0; // copy known messages pduIdx = 0; while (pduIdx < _pdus.Count) { sms = _pdus[pduIdx]; slot = await sms.get_slot(); idx = ((slot) >> (3)); if (idx < (newBitmap).Length) { bitVal = ((1) << ((((slot) & (7))))); if ((((newBitmap[idx]) & (bitVal))) != 0) { newArr.Add(sms); if (await sms.get_concatCount() == 0) { newMsg.Add(sms); } else { sig = await sms.get_concatSignature(); i = 0; while ((i < nsig) && ((sig).Length > 0)) { if (signatures[i] == sig) { sig = ""; } i = i + 1; } if ((sig).Length > 0) { signatures.Add(sig); nsig = nsig + 1; } } } } pduIdx = pduIdx + 1; } // receive new messages slot = 0; while (slot < nslots) { idx = ((slot) >> (3)); bitVal = ((1) << ((((slot) & (7))))); prevBit = 0; if (idx < (prevBitmap).Length) { prevBit = ((prevBitmap[idx]) & (bitVal)); } if ((((newBitmap[idx]) & (bitVal))) != 0) { if (prevBit == 0) { sms = await this.fetchPdu(slot); newArr.Add(sms); if (await sms.get_concatCount() == 0) { newMsg.Add(sms); } else { sig = await sms.get_concatSignature(); i = 0; while ((i < nsig) && ((sig).Length > 0)) { if (signatures[i] == sig) { sig = ""; } i = i + 1; } if ((sig).Length > 0) { signatures.Add(sig); nsig = nsig + 1; } } } } slot = slot + 1; } _pdus = newArr; // append complete concatenated messages i = 0; while (i < nsig) { sig = signatures[i]; cnt = 0; pduIdx = 0; while (pduIdx < _pdus.Count) { sms = _pdus[pduIdx]; if (await sms.get_concatCount() > 0) { if (await sms.get_concatSignature() == sig) { if (cnt == 0) { cnt = await sms.get_concatCount(); newAgg.Clear(); } newAgg.Add(sms); } } pduIdx = pduIdx + 1; } if ((cnt > 0) && (newAgg.Count == cnt)) { sms = new YSms(this); await sms.set_parts(newAgg); newMsg.Add(sms); } i = i + 1; } _messages = newMsg; return(YAPI.SUCCESS); }