api - sending bulk sms to group using vb.net -
i connected sms provider api using vb.net
i have created grouping table , inserted numbers in grouping , reach each row , send trigger api process sending. sms not reached grouping members, delivered first mobile number in group.
how solve problem ? think have set delay between each sending , did no use. code below :
function getgroupsmobilenumbers() arraylist dim mobilenumbersarraylist new arraylist each contact filspaycomponent.contactaddress in filspaycomponent.contactaddress.getallcontactaddressbygroupid(ddlgroup.selectedvalue) mobilenumbersarraylist.add(contact.mobile) next homecoming mobilenumbersarraylist end function protected sub btnsend_click(byval sender object, byval e system.eventargs) handles btnsend.click if ddlgroup.selectedvalue = 0 lbresult.text = "no groups selected" exit sub end if dim mobilenumbersarraylist arraylist mobilenumbersarraylist = getgroupsmobilenumbers() if mobilenumbersarraylist.count = 0 lbresult.text = "group doesnt contain numbers" exit sub end if dim totalno integer = filspaycomponent.contactaddress.addresscontactscount(ddlgroup.selectedvalue) if mobilenumbersarraylist.count * messagecount.value <= filspaycomponent.smsuser.getsmsuserbyuserid(context.user.identity.name).balance dim txtmsg string dim smstype integer if hidunicode.value <> "1" txtmsg = txtmessage.text smstype = 1 else txtmsg = converttexttounicode(txtmessage.text) smstype = 2 end if dim x integer 'for each contact filspaycomponent.contactaddress in filspaycomponent.contactaddress.getallcontactaddressbygroupid(ddlgroup.selectedvalue) each contact in mobilenumbersarraylist.toarray dim tomobile string = contact.mobile if tomobile.length > 10 dim execarraylist arraylist execarraylist = sendsms(tomobile, txtmsg, smstype) '-- give excution more time if execarraylist.count < 1 threading.thread.sleep(1000) end if '-- give excution more time if execarraylist.count < 1 threading.thread.sleep(1000) end if '-- give excution more time if execarraylist.count < 1 threading.thread.sleep(1000) end if x = x + 1 ' lbresult.text = "sent successfully" end if next filspaycomponent.smsuser.removesmscredit(context.user.identity.name, messagecount.value * x) dim newsmsarchiveitem new filspaycomponent.smsarchive newsmsarchiveitem.frommobile = txtsenderid.text newsmsarchiveitem.tomobile = "0" newsmsarchiveitem.groupid = ddlgroup.selectedvalue newsmsarchiveitem.datesent = datetime.now newsmsarchiveitem.msg = txtmessage.text newsmsarchiveitem.groupcount = x newsmsarchiveitem.optional1 = context.user.identity.name newsmsarchiveitem.optional2 = "1" newsmsarchiveitem.messageno = messagecount.value seek newsmsarchiveitem.addsmsarchive() lbresult.text = "message sent successfully" btnsend.visible = false grab ex exception lbresult.text = ex.message end seek else lbresult.text = "not plenty credit, please refill " end if end sub sub sendsms(byval tomobile string, byval txtmsg string, byval smstype integer) dim hwreq httpwebrequest dim hwres httpwebresponse dim smsuser string = "xxxxxx" dim smspassword string = "xxxxxx" dim smssender string = "xxxxxx" dim strpostdata string = string.format("username={0}&password={1}&destination={2}&message={3}&type={4}&dlr=1&source={5}", server.urlencode(smsuser), server.urlencode(smspassword), server.urlencode(tomobile), server.urlencode(txtmsg), server.urlencode(smstype), server.urlencode(smssender)) dim strresult string = "" seek hwreq = directcast(webrequest.create("http://xxxxx:8080/bulksms/bulksms?"), httpwebrequest) hwreq.method = "post" hwreq.contenttype = "application/x-www-form-urlencoded" hwreq.contentlength = strpostdata.length dim arrbytedata byte() = asciiencoding.ascii.getbytes(strpostdata) hwreq.getrequeststream().write(arrbytedata, 0, arrbytedata.length) hwres = directcast(hwreq.getresponse(), httpwebresponse) if hwres.statuscode = httpstatuscode.ok dim srdrresponse new streamreader(hwres.getresponsestream(), encoding.utf8) dim strresponse string = srdrresponse.readtoend().trim() select case strresponse case "01" strresult = "success" exit select case else strresult = "error: " + strresponse exit select end select end if grab wex webexception strresult = "error, " + wex.message grab ex exception strresult = "error, " + ex.message hwreq = nil hwres = nil end seek end sub
if function getgroupsmobilenumbers()
not homecoming array list of numbers (as strings) comment out. mobilenumbersarraylist = getgroupsmobilenumbers()
utilize commented out code below (with 3 of own tel. numbers) set testing.
private sub btnsend_click(byval sender system.object, byval e system.eventargs) handles btnsend.click if ddlgroup.selectedvalue = 0 lbresult.text = "no groups selected" exit sub end if dim mobilenumbersarraylist new arraylist mobilenumbersarraylist = getgroupsmobilenumbers() 'mobilenumbersarraylist.add("07702123456") 'mobilenumbersarraylist.add("07702123457") 'mobilenumbersarraylist.add("07702123458") if mobilenumbersarraylist.count = 0 lbresult.text = "group doesnt contain numbers" exit sub end if dim totalno integer = filspaycomponent.contactaddress.addresscontactscount(ddlgroup.selectedvalue) if mobilenumbersarraylist.count * messagecount.value <= filspaycomponent.smsuser.getsmsuserbyuserid(context.user.identity.name).balance dim txtmsg string dim smstype integer if hidunicode.value <> "1" txtmsg = txtmessage.text smstype = 1 else txtmsg = converttexttounicode(txtmessage.text) smstype = 2 end if dim x integer each contact in mobilenumbersarraylist if contact.length > 10 sendsms(contact, txtmsg, smstype) x = x + 1 end if next filspaycomponent.smsuser.removesmscredit(context.user.identity.name, messagecount.value * x) dim newsmsarchiveitem new filspaycomponent.smsarchive newsmsarchiveitem.frommobile = txtsenderid.text newsmsarchiveitem.tomobile = "0" newsmsarchiveitem.groupid = ddlgroup.selectedvalue newsmsarchiveitem.datesent = datetime.now newsmsarchiveitem.msg = txtmessage.text newsmsarchiveitem.groupcount = x newsmsarchiveitem.optional1 = context.user.identity.name newsmsarchiveitem.optional2 = "1" newsmsarchiveitem.messageno = messagecount.value seek newsmsarchiveitem.addsmsarchive() lbresult.text = "message sent successfully" btnsend.visible = false grab ex exception lbresult.text = ex.message end seek else lbresult.text = "not plenty credit, please refill " end if end sub
this btnsend
sub should work if rest of code okay. note line.
dim totalno integer = filspaycomponent.contactaddress.addresscontactscount(ddlgroup.selectedvalue)
doesn't appear anything. if need set delay improve off turning sendsms
function returns sent confirmation btnsend
loop. texting apis can handle lists of numbers rather waiting response each text message. afterall added queue @ end.
vb.net api sms sms-gateway bulksms
No comments:
Post a Comment